import javax.swing.*;
class bin_dec{
public static void main(String args[]){
int bin, dec, i, x;
String inp;
//bin = Integer.parseInt(args[0]);
inp = JOptionPane.showInputDialog("Enter a Binary
Number:");
bin = Integer.parseInt(inp);
i=0;
dec = 0;
while(bin != 0){
x = bin % 10;
dec += x * Math.pow(2,i);
bin /= 10;
i++;
}
System.out.println("Decimal: " + dec);
}
}
class bin_dec{
public static void main(String args[]){
int bin, dec, i, x;
String inp;
//bin = Integer.parseInt(args[0]);
inp = JOptionPane.showInputDialog("Enter a Binary
Number:");
bin = Integer.parseInt(inp);
i=0;
dec = 0;
while(bin != 0){
x = bin % 10;
dec += x * Math.pow(2,i);
bin /= 10;
i++;
}
System.out.println("Decimal: " + dec);
}
}
Comments
Post a Comment
share your thoughts ....