我有一个带字节值的 String[]
String[] s = {"110","101","100","11","10","1","0"};
循环遍历 s,我想从中获取 int 值。
我正在用这个
Byte b = new Byte(s[0]); // s[0] = 110
int result = b.intValue(); // b.intValue() is returning 110 instead of 6
由此,我试图得到结果,{6, 5, 4, 3, 2, 1}
我不确定从这里去哪里。我能做什么?
谢谢大家。问题已回答。
最佳答案
您可以使用重载的 Integer.parseInt(String s, int radix)
这种转换的方法。这样您就可以跳过 Byte b = new Byte(s[0]);
这段代码。
int result = Integer.parseInt(s[0], 2); // radix 2 for binary
关于java - 如何将二进制表示形式的字节转换为java中的int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22293546/