First, Java supports decimal, octal, and hexadecimal, but does not support binary
Java supports decimal:
Java indicates that decimal does not require any processing of numbers
Java represents the decimal int a = 13; System.out.println ("Java represents decimal:" +a);
Operation Result:
Java supports octal:
Java represents octal, preceded by "0"
Java represents octal int b = 013; System.out.println ("Java represents octal:" +b);
Operation Result:
Java Support hex
When Java represents hexadecimal, it starts with "0x"
Java represents the hexadecimal int c = 0x13; System.out.println ("Java represents hexadecimal:" +c);
Operation Result:
Java does not explicitly support binary
Because the binary is too long,only strings can be used in Java to represent the binary
Second, the Java operation mode
Described above, Java Support decimal, octal, hexadecimal, but the careful small partner immediately found that the result of the above is not what we want to specify the number of numbers, but unified in decimal notation, which shows thatJava in the operation always use binary as the method of operation.
Three, the conversion of the input system
Integer converted to string
First, declare a decimal integer number:
int result = 13;
octal, decimal
The result is converted from decimal to octal string octalstr = integer.tooctalstring (result); System.out.println (OCTALSTR);
Operation Result:
hexadecimal, decimal
Converts result from decimal to hexadecimal string hexstr = integer.tohexstring (result); System.out.println (HEXSTR);
Operation Result:
decimal--Binary
The result is converted from decimal to binary string binarystr = integer.tobinarystring (result); System.out.println (BINARYSTR);
Operation Result:
The string is converted to an integral type:
interger.valueof (string, Binary) method to convert decimal to an integer representation of the other binary
String resultstr = "13";//convert to octal result = integer.valueof (ResultStr, 8); System.out.println ("converted into octal:" +result); result = Integer.valueof (resultstr,16); System.out.println ("to Hex:" +result);
Operation Result:
So what happens now when we turn retultstr into binary?
result = Integer.valueof (resultstr,2); System.out.println ("Into binary:" +result);
Operation Result:
It turns out thatJava really cannot represent the binary in integer form
Java binary and data type (i)