HEX编码(Hexadecimal Code),也就是十六进制编码。
多字节的 HEX编码存储使用常见的 INTEL字节序方式(HEX(I))和MOTOROLA字节序方式(HEX(M))。 INTEL编码方式为大端字节序的方式,MOTOROLA编码方式为小端字节序的方式。
下面的代码之小端字节序转换成int的算法:
public static int byte2int(byte[] b) {
int res = 0;
int bLen = b.length;
if (bLen < 5) {// int 最大到4个字节
for (int i = 0; i < bLen; i++) {
res += (b[i] & 0xFF) << (8 * i);
}
}
return res;
}