In this section, you will learn to convert decimal number into binary. The java.lang package provides the functionality to convert a decimal number into a binary number.
Description of program:
This program takes a decimal number from console and it converts it into binary format using the toBinaryString() method. Input number is taken as string so convert it into an integer data using the Integer.parseInt() method. To convert the Decimal number into binary number use toBinaryString() method.
This method takes an integer type value and returns its string representation of integer values which represents the data in binary. The base of binary number is 2.
Here is the code of this program:
Output of this program:
Enter the decimal value:
Posted on: May 31, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles