Decimal To Binary Conversion

in Hindi - Decimal To Binary Conversion



not yet

Source Code :

RUNimport java.util.Scanner;

public class DectoBin
{
public static void main(String args[]){ 

int num, rem=0, num1=0, i=0;
System.out.println("Enter decimal value(0 to 9): ");
Scanner enter = new Scanner(System.in);
num = enter.nextInt(); 

while(num > 0){
rem = num % 2;
num1 = num1 + rem * (int)Math.pow(10, i);
i++;
num = num / 2 ;
}
System.out.println("Binary number = " + num1);

}
}