Site icon WebArtDeveloper

How to Create a Program to Convert a Decimal Number into Binary Number in Core Java

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);
}
}

https://youtu.be/6o_Q1Mq7u0Q

Exit mobile version