In this section, you will learn to convert a number to a binary (0,1). The given number is a decimal format and the following program to calculate its binary.
Code Description:
This program takes a decimal number at the console. This number is as a string format so, it must be converted into an integer type data using the Integer.parseInt() method. The toBinaryString() method is used for converting an integer type data into a binary.
Here is the code of this program:
import java.io.*;
|
Output of this program given below.
| C:\corejava>java NumberToBinary Enter any number: 25 Binary number is:11001 C:\corejava> _ |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Convert Number to Binary View All Comments
Post your Comment