Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Thursday, 21 April 2011

Java program to conver any integer into binary form

import java.util.*;
class binary
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a,d;
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();
int b1,b2,b3,b4,b5,b6,b7,b8;

b1=a%2;
    d=a/2;
b2=d%2;
    d=d/2;

b3=d%2;
    d=d/2;

b4=d%2;
    d=d/2;

b5=d%2;
    d=d/2;

b6=d%2;
    d=d/2;

b7=d%2;
    d=d/2;

b8=d%2;
   
System.out.print ("\n\t Binary of "+a+" is = ");
System.out.print (b8);
System.out.print (b7);
System.out.print (b6);
System.out.print (b5);
System.out.print (b4);
System.out.print (b3);
System.out.print (b2);
System.out.print (b1);
}
}

No comments:

Post a Comment