O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting an Integer to Binary, Octal, and Hexadecimal

int intValue = 24;
											String binaryStr = Integer.toBinaryString(intValue);
											String octalStr = Integer.toOctalString(intValue);
											String hexStr = Integer.toHexString(intValue);

Using the Integer class, it is easy to convert an integer value from decimal to binary, octal, or hexadecimal. The relevant static methods on the Integer class are the toBinaryString(), toOctalString(), and toHexString() methods. In this phrase, we use each of these methods—each time passing in an integer value and getting a String returned that contains the integer in binary, octal, and hex format, respectively.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required