CopyPastehas never been so tasty!

Convert - Parse decimal into binary in java

by anonymous

  • 0
  • 0
  • 0

Convert - Parse decimal into binary in java

Binary Type:The Binary number system is another way to represent quantities. It is easy than the decimal system because it has only two digits (bits). The two binary digits are 1 and 0.Counting in BinaryBegin counting: 0, 1.If another digit is included then it will be like 10, 11.With three digit position you can continue to count as 100, 101, 110 and 111 and for fourth digit we will continue onwards.Conversion of decimal into binary number:The java.lang package helps to convert a decimal number into a binary number. This program takes a decimal number and converts it into binary form using the toBinaryString () method. Buffered Reader reads text from an input stream and provides reading of characters, arrays, and lines. The buffer size can be fixed.Here is simple code to convert decimal into binary number.

import java.lang.*;


public class DecimalToBinary{

  public static void main(String args[ ]) throws IOException{

  BufferedReader bf = new BufferedReader(new InputStreamReader(;

  System.out.println("Enter the decimal value:      ");

  String hex = bf.readLine();

  int i = Integer.parseInt(hex); 

  String by = Integer.toBinaryString(i);

  System.out.println("Binary: " + by);


This simple article tells that how we can convert decimal into binary number.

Add A Comment: