In this tutorial how to convert a decimal number into binary number in Core Java is shown.
Code:
Binary.java
import static java.lang.Math.pow;
class D2B
{
public static void main(String args[])
{
int number=Integer.parseInt(args[0]),binary=0,r,copyn,i=0;
copyn=number;
while(copyn>0)
{
r=copyn%2;
binary=binary+(int)(r*pow(10,i++));
copyn/=2;
}
System.out.println(“D2B of “+number+” is “+binary);
}
}