首页 > 解决方案 > ByteBuffer 分配为第一个 - little endian

问题描述

如何首先获取字节数组中的数字,例如:\xb6\x00\x00\x00\x00\x00\x00

byte[] totalChunksData = ByteBuffer.allocate(8).putInt(182).array();
result: \x00\x00\x00\xb6\x00\x00\x00\x00

标签: javaandroid

解决方案


只需使用order(ByteOrder.LITTLE_ENDIAN)方法:

byte[] totalChunksData = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putInt(182).array();

推荐阅读