public class Binpow
{
public int pow(int n)
{
int res=1;
if(n!=0)
{
for(int i=1;i<=n;i++)
res=2*res;
n++;
}
return res;
}
}
import java.io.*;
public class Binary extends Binpow
{
int g=1;
int bin;
int dec;
int rem=1;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER the binary number");
bin=Integer.parseInt(br.readLine());
}
public void output()
{
}
public void cal()
{
int n=0;
int h=0;System.out.println("check");
while(rem!=0||bin!=0)
{
rem=bin%10;
bin=bin/10;
h=pow(n);
dec=rem*h+dec;
n++;
}
System.out.println("decimal number ="+dec);
}
}
import java.io.*;
public class Bimain
{
public static void main(String[] arg)
throws IOException
{
Binary c=new Binary();
c.input();
c.cal();
}
}


No comments:
Post a Comment