/*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. -*/
class deci
{
public static void convertBinary(int num)
{
int binary[] = new int[40];
int index = 0;
while(num > 0){
binary[index++] = num%2;
num = num/2;
}
for(int i = index-1;i >= 0;i--){
System.out.print(binary[i]);
}
}
public static void main(String a[])
{
System.out.println("Binary representation of 124: ");
convertBinary(124);
System.out.println("\nBinary representation of 45: ");
convertBinary(45);
System.out.println("\nBinary representation of 999: ");
convertBinary(999);
}
}
class deci
{
public static void convertBinary(int num)
{
int binary[] = new int[40];
int index = 0;
while(num > 0){
binary[index++] = num%2;
num = num/2;
}
for(int i = index-1;i >= 0;i--){
System.out.print(binary[i]);
}
}
public static void main(String a[])
{
System.out.println("Binary representation of 124: ");
convertBinary(124);
System.out.println("\nBinary representation of 45: ");
convertBinary(45);
System.out.println("\nBinary representation of 999: ");
convertBinary(999);
}
}
No comments:
Post a Comment