import java.io.*;
class BtoD
{
public static void main()throws IOException
{
DataInputStream k=new DataInputStream(System.in);
System.out.println("enter a number");
n=Integer.parseInt(k.readLine());
int r;double s=0,i=0;
while(n>0)
{
r=n%10;
s=s+r*Math.pow(2,i);
n=n/10;
i++;
}
System.out.println(s);
}
}
-----------------------OUTPUT----------------------------------
Enter number-:10
2
class BtoD
{
public static void main()throws IOException
{
DataInputStream k=new DataInputStream(System.in);
System.out.println("enter a number");
n=Integer.parseInt(k.readLine());
int r;double s=0,i=0;
while(n>0)
{
r=n%10;
s=s+r*Math.pow(2,i);
n=n/10;
i++;
}
System.out.println(s);
}
}
-----------------------OUTPUT----------------------------------
Enter number-:10
2

Comments (0)
Post a Comment