Table of Contents
Java program to convert decimal to binary
Decimal number have base 10 and they ranges from 0 to 9.
Binary number have base 2 and they ranges from 0 to 1.
Following is the java program to convert decimal to binary.
Logic to convert decimal to binary in java
//always check name of class
import java.util.*;
//itvoyagers.in
class DecToBin
{
public static void main(String agr[])
{
int[] bin = new int[16];
Scanner in = new Scanner(System.in);
System.out.println("Enter any number : ");
int dnum = in.nextInt();
int i;
for(i = 0; dnum>0; i++)
{
bin[i] = dnum % 2;
dnum = dnum / 2;
}
for(int j=i-1; j>=0; j--)
{
System.out.print(bin[j]);
}
}
}
Output :
Enter any number :
54
110110
PRACTICALS/PRACTICE PROGRAM IN Java
CHECKOUT OTHER RELATED TOPICS
We are aiming to explain all concepts of Java in easiest terms as possible.

ITVoyagers
Author