תנסה:
קוד:
System.out.println(Integer.parseInt("110", 2));
כאשר ה 110 הוא המס' הבינארי.
או שתנסה את זה:
קוד:
class Test
{
static int a [] = {1,0,0};
static int ConvertBinaryToDecimal(int[] bin) {
String s="";
for (int i=0;i<bin.length ;i++ )
{
s = s+bin ;
}
return Integer.parseInt(s,2);
}
public static void main(String[] args) {
System.out.println("Decimal\t"+ConvertBinaryToDecimal(a));
}
}
שלקוח מ
הפורומים של Java (הפוסט האחרון)