**Java Program to Convert Decimal Number into Binary Form**

This tutorial demonstrates about how to convert given decimal number into the binary means machine language form usign java program.

**What is Decimal Number?**

The numbers we use in everyday life are decimal numbers Ex- (0,1,2,3,4,5,6,7,8 and 9).

The decimal numeral system is the most usual way of writing numbers. It has ten as a starting point, or base.

**What is Binary Number?**

The binary numeral system is a way to write numbers using only two digits: 0 and 1.

The computer machine only understands the language by converting decimal number into binary form.

**Decimal to Binary Conversion Method **

**Example - Convert Decimal Number into Binary Number**

**Steps**

- Accept the integer number from user
- Find the remainder of given number dividing by 2
- Divide the given number by 2
- Hold the given number as a new divided number
- Concatenate the remainder into string type
- Repeat from step 2 until the new divided number is > 0
- Display Concatenated string as in reverse order

import java.util.Scanner;
public class DecimalToBinaryEx
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int decimal,rem,div=0;
String binary="";
System.out.print("Enter any number : ");
decimal = scan.nextInt();
while(decimal > 0) //
{
rem = decimal % 2; // find remainder
div = decimal / 2; // divide given num by 2
decimal = div; // hold new number for div by 2
binary += Integer.toString(rem); //convert int to string and concate remainder into string
}
System.out.print("Binary : ");
for(int i=binary.length()-1;i>=0;i--) // display in reverse order
System.out.print(binary.charAt(i)); // prints single character
}
}

**Output**

Enter any number : 13

Binary : 1101

We can use StringBuffer's **reverse()** method to reverse the String as

StringBuffer sb = new StringBuffer(binary);
System.out.println("Binary : "+sb.reverse());