CONVERTING BINARY NUMBER TO DECIMAL NUMBER
What are binary numbers?
Ans : Binary is a base 2 number system invented by Gottfried Leibniz that is made up of only two numbers: 0 and 1. This number system is the basis for all binary code, which is used to write data such as the instructions that computer processors use, or the digital text you read every day.
PROGRAM
import java.lang.*;
import java.util.*;
class binary_to_decimal
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int i=0,d,n;
double s=0;
System.out.print("Enter a binary digit : ");
n=sc.nextInt();
while(n>0)
{
d=n%10;
s=s+d*Math.pow(2,i);
i++;
n=n/10;
}
System.out.print("The number is : "+s);
}
}
OUTPUT
0 Comments