Home >Java >javaTutorial >Summary of Java's medium-base conversion functions
The following editor will bring you a detailed explanation of the hexadecimal conversion function based on Java. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.
Convert decimal to hexadecimal:
Integer.toHexString(int i)
Convert decimal to octal
Integer.toOctalString(int i)
Convert decimal to binary
Integer.toBinaryString(int i)
Convert hexadecimal to decimal
Integer.valueOf("FFFF",16).toString()
Convert octal to decimal
Integer.valueOf("876",8).toString()
Convert binary to decimal
Integer.valueOf("0101",2).toString()
Is there any way to directly convert 2 ,8,16 hexadecimal directly converted to decimal?
java.lang.Integer类 parseInt(String s, int radix)
Parses the string argument into a signed integer using the base specified by the second argument.
examples from jdk: parseInt("0", 10) returns 0 parseInt("473", 10) returns 473 parseInt("-0", 10) returns 0 parseInt("-FF", 16) returns -255 parseInt("1100110", 2) returns 102 parseInt("2147483647", 10) returns 2147483647 parseInt("-2147483648", 10) returns -2147483648 parseInt("2147483648", 10) throws a NumberFormat Exception parseInt("Kona", 10) throws a NumberFormatException parseInt("Kona", 27) returns 411787
Base conversionHow to write (two, eight, sixteen) without algorithm
Integer.toBinaryString Integer.toOctalString Integer.toHexString
The above is the detailed content of Summary of Java's medium-base conversion functions. For more information, please follow other related articles on the PHP Chinese website!