In this section, you will learn how to convert an integer type data into binary, octal and hexadecimal. The java.lang package provides the facility for converting the data integer into binary, octal, and hexadecimal. The following program helps you to convert into these. toBinaryString() method converts integer type data into binary, toHexString() method converts integer type into hexadecimal and toOctalString() method converts integer into octal type data.
Description of code:
This is the method that takes an integer type value and returns the string representation of unsigned integer value that will represent the data in binary (base 2).
This is the method that takes an integer type value and converts in hexadecimal or in an unsigned integer (base 16).
This is the method that takes an integer type value and converts it into octal type data. The octal type data has base 8.
Here is the code of program:
Output of program:
Data types conversion example!
Hexa decimal: 32
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: June 8, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles