import java.io.*;
class BintoDec
{
public static void main(String args[])
{
int a,dec=0;
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter Binary Number to Convert");
int bin=Integer.parseInt(cin.readLine());
for(int i=0;bin>0;i++)
{
a=bin%10;
dec=dec+a*((int)Math.pow(2,i));
bin=bin/10;
}
System.out.println("Given Binary number conversion in Decimal is = "+dec);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class BintoDec
{
public static void main(String args[])
{
int a,dec=0;
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter Binary Number to Convert");
int bin=Integer.parseInt(cin.readLine());
for(int i=0;bin>0;i++)
{
a=bin%10;
dec=dec+a*((int)Math.pow(2,i));
bin=bin/10;
}
System.out.println("Given Binary number conversion in Decimal is = "+dec);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
No comments:
Post a Comment