Binary swap to Decimal method, for example:
Binary number: 11001
Decimal number: 1*24+1*23+0*22+0*21+1*20=25
Octal to decimal method, for example:
Octal Number: 32007
Decimal number: 3*84+2*83+0*82+0*81+7*80=13319
Hexadecimal swap method for decimal, for example:
Hexadecimal number: a20f (because the hexadecimal number is represented by a~f between 10~15, so the calculation will a~f with 10~15)
Decimal number: 10*83+2*82+0*81+15*80=41487
Through the above two or eight, hexadecimal decimal number of the calculation method, you can calculate the code is:
//Parameter Num is the number that needs to be converted, n is the binary of the number
public string ToD (string Num, int n)
{
char[] Nums=num.tochararray ();
int d = 0;
for (int i = 0; I <nums. Length; i++)
{
String number=nums [i]. ToString ();
if (n = =)
{
Switch (number. ToUpper ())
{
Case "A":
Number = "Ten";
Break
Case "B":
Number = "one";
Break
Case "C":
Number = "a";
Break
Case "D":
Number = ";"
Break
Case "E":
Number = "number";
Break
Case "F":
Number = ";"
Break
}
}
Double power = Math.pow (Convert.todouble (n), COnvert. ToDouble (nums. Length-(i + 1));
D = d + convert.toint32 (number) * CONVERT.TOINT32 (Power);
}
return d.tostring ();
}