Here is the sample code, which we implemented directly through the methods in the JDK repository, as follows:
1 PackageCom.himi.radix;2 3 4 /**5 * How to implement decimal to other binary conversions in Java6 * @authorHebao7 *8 */9 Public classIntegertoother {Ten One Public Static voidMain (string[] args) { A intn = 14; - // decimal turns into 16 binary: -String N0 =integer.tohexstring (n); theSystem.out.println ("0x" +n0.touppercase ()); - //decimal into octal -String N1 =integer.tooctalstring (n); - System.out.println (N1); + //decimal turns into binary -String N2 = integer.tobinarystring (12); + System.out.println (n2); A at // hex turns into decimal -String n3 = integer.valueof ("FFFF", 16). toString (); - System.out.println (N3); - //Hex turns binary -String N4 = integer.tobinarystring (integer.valueof ("FFFF", 16)); - System.out.println (N4); in //hex turns into octal -String N5 = integer.tooctalstring (integer.valueof ("FFFF", 16)); to System.out.println (N5); + - the // octal turns into decimal *String N6 = integer.valueof ("576", 8). toString (); $ System.out.println (N6); Panax Notoginseng //octal turns into binary -String N7 = integer.tobinarystring (integer.valueof ("23", 8)); the System.out.println (N7); + //octal turns into hexadecimal AString n8 = integer.tohexstring (integer.valueof ("23", 8)); the System.out.println (N8); + - $ //Binary goto decimal $String N9 = integer.valueof ("010110101010", 2). toString (); - System.out.println (N9); - //Binary turn octal theString N10 = integer.tooctalstring (Integer.parseint ("010110101010", 2)); - System.out.println (N10); Wuyi //Binary turn hex theString N11 = integer.tohexstring (Integer.parseint ("010110101010", 2) . toUpperCase (); -System.out.println ("0x" +N11); Wu - } About $}
Program run effect, as follows:
How to implement decimal to other binary conversions in Java Basics hardening 106:java