10010001110001111010100011000000 这个就是数据,他是一个负数。使用API提示numberformat。
求解答
public static void main(String[] args) {
String a = "10010001110001111010100011000000 ";
int x =0;
for(char c: a.toCharArray()){
x = x * 2 + (c == '1' ? 1 : 0);
}if(a.substring(0,1).equals("1")){
x=-x;
}
System.out.println(x);
}
这种比较原始的方式可以满足你的要求
但是应该有其他更方便的方式