首先,这听起来像是这里的问题: How to convert a byte array to its numeric value (Java)?
但是我的字节数组的起源是一个字符串,如下所示:
byte[] foo = new byte[8];
foo = "12345678".getBytes();
有没有比
更快的方法(是的,确实是快速做到这一点)
Integer.parseInt(new String(foo))
?
字符串仅包含代表整数的数字。
最佳答案
试试这个
int res = 0;
for(int i = foo.length -1, m = 1; i >=0; i--, m *= 10) {
res += (foo[i] & 0xF) * m;
}
关于java - 将字节数组转换为相应整数的快速方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21076399/