Decimal to Binary Number Converter in Java Program

Number Conversion: Converting decimal to Binary number format using Java Coding


If you want to convert the decimal number to binary number just use the below program. The conversion is done by using the method Integer.toBinaryString. In this program I just get the input from the user using BufferedReader and input stream.
Source code program
Decimal2Binary.java

import java.lang.*;
import java.io.*;
public class Decimal2Binary{
public static void main(String args[]) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal value:");
String decimal = bf.readLine();
int i = Integer.parseInt(decimal);
String by = Integer.toBinaryString(i);
System.out.println("Binary: " + by);
}
}

The Output of the above program will be

D:Java est>java Decimal2Binary
Enter the decimal value:
101
Binary: 1100101

D:Java est>


You can also try the online Decimal to Binary, Hexa, Octal Converter to check the output of this program.


Related Topic Java Program for Decimal to Hex converter
Binary Subtraction in Java
Decimal to Binary Number Converter in C Program
Convert Decimal to Hex in PHP
Binary to Decimal Conversion
Java  

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback