# How to implement decimal to other binary conversions in Java Basics hardening 106:java

Source: Internet
Author: User

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

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.