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 methodseach time passing in an integer value and getting a String returned that contains the integer in binary, octal, and hex format, respectively.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net