Program
import java.util.Scanner;
public class Demo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
long binaryNumber, decimalNumber = 0, j = 1, rem;
System.out.print("Enter a binary number: ");
binaryNumber = sc.nextLong();
while (binaryNumber != 0)
{
rem = binaryNumber % 10;
decimalNumber = decimalNumber + rem * j;
j = j * 2;
binaryNumber = binaryNumber / 10;
}
System.out.println("Decimal Number: " + decimalNumber);
}
}
Output:
Enter a binary number: 10011001000
Decimal Number: 1224
Enter a binary number : 1010
Decimal Number: 10
For latest job updates join Telegram Channel: https://t.me/sateeshm