Numeral systems in Java
Forums:
//decimal number system
int decimal = 42;
//octal number system
int octal = 042;
//octal is 34
//hexadecimal number system
int hexadecimal = 0x42;
//hexadecimal is 66
//binary number system
int binary = 0b1010;
//binary is 10
//42 to decimal string
String sDecimal = Integer.toString(42);
//sDecimal is "42"
//42 to octal string
String sOctal = Integer.toString(42, 8);
//sOctal is "52"
//42 to hexadecimal string
String sHexadecimal = Integer.toString(42, 16);
//sHexadecimal is "2a"
//42 to binary string
String sBinary = Integer.toString(42, 2);
//sBinary is "101010"
- Log in to post comments