可以使用 Java 的位运算来将长度为 4 的 byte 数组转换为十进制数,具体的方法如下:

public static int byteArrayToDecimal(byte[] byteArray) {
    int result = 0;
    for (int i = 0; i < byteArray.length; i++) {
        result += (byteArray[i] & 0xFF) << (8 * (byteArray.length - 1 - i));
    }
    return result;
}

使用示例:

byte[] byteArray = {0x01, 0x23, 0x45, 0x67};
int decimal = byteArrayToDecimal(byteArray);
System.out.println(decimal);

输出结果为: 19088743


原文地址: https://www.cveoy.top/t/topic/psQl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录