Numeral systems in C#
Forums:
//decimal number system
int nDecimal = 42;
//octal number system
int octal = Convert.ToInt32("42", 8);
//octal is 34
//hexadecimal number system
int hexadecimal = 0x42;
//hexadecimal is 66
//binary number system
int binary = Convert.ToInt32("1010", 2);
//binary is 10
//42 to decimal string
string sDecimal = 42.ToString();
//sDecimal is "42"
//42 to octal string
string sOctal = Convert.ToString(42, 8);
//sOctal is "52"
//42 to hexadecimal string
string sHexadecimal = Convert.ToString(42, 16);
//sHexadecimal is "2a"
//42 to binary string
string sBinary = Convert.ToString(42, 2);
//sBinary is "101010"
- Log in to post comments