➽ Program:-
import
java.util.*;
class
Main
{
public static void main(String args[])
{
int
number, binary_value, decimal_value = 0, base = 1, rem;
Scanner s = new Scanner(System.in);
System.out.print("Enter a Binary
Number(In 0s and 1s): ");
number = s.nextInt();
binary_value = number;
while(number > 0)
{
rem = number % 10;
decimal_value += rem * base;
number = number / 10 ;
base = base * 2;
}
System.out.print("Decimal
Equivalent of "+binary_value+" is "+decimal_value);
}
}
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.