You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
751 B
Java

/*
Write a program to convert decimal number to binary format using numeric operations. Below example shows how to convert decimal number to binary format using numeric operations.
*/
public class DecimalToBinary
{
public void printBinaryFormat(int number)
{
int binary[] = new int[25];
int index = 0;
while(number > 0)
{
binary[index++] = number%2;
number = number/2;
}
for(int i = index-1; i >= 0; i--)
{
System.out.print(binary[i]);
}
}
public static void main(String a[])
{
DecimalToBinary dtb = new DecimalToBinary();
dtb.printBinaryFormat(25);
}
}