Number system program code to convert of Decimal numbers to Binary numbers in Java

class Dec2Bin
{
public static void main(String args[])
{
int decN=137, binN=0, i=1, j, tmp;
tmp=j=decN;
while(j>0)
{
binN=binN+(decN%2)*i;
decN/=2;
j/=2;
i*=10;
}
System.out.println("Decimal Number is: "+tmp);
System.out.println("Binary Number is:   "+binN);
}
}





No comments

Post your comments

Powered by Blogger.