decimal to binary java program

Decimal to Binary Number Program in Java

import java.util.Scanner; /** * * @author AFAQ */ public class DecimalToBinary { public static void main(String[] args) { int decimal; Scanner sc = new Scanner(System.in); System.out.print(“Enter decimal number=”); decimal = sc.nextInt(); String binary = “”; while (decimal > 0) { binary= decimal % 2 + binary ; decimal = decimal / 2; } System.out.println(“Binary=”+binary); } […]

Binary to Decimal Number Program in Java

import java.util.Scanner; /** * * @author AFAQ */ public class BinaryToDecimal { public static void main(String[] args) { int binary; Scanner sc = new Scanner(System.in); System.out.print(“Enter binary number=”); binary = sc.nextInt(); int decimal = 0; int n = 0; while (binary>0) { int temp = binary % 10; decimal += temp * Math.pow(2, n); binary […]