字节序

什么是大小端?

例如:
90AB12CD
In big endian, you store the most significant byte in the smallest address. Here’s how it would look:

AddressValue
100090
1001AB
100212
1003CD

In little endian, you store the least significant byte in the smallest address. Here’s how it would look:

AddressValue
1000CD
100112
1002AB
100390

从Audio Recorder里读出来的byte array 数据是小端的, 可以用以下的代码转成Short

    public static short[] bytesToShorts(byte[] b) {
        short[] s = new short[b.length / 2];
        for (int i = 0; i < s.length; i++) {
            s[i] = (short) ((b[i * 2] & 0xff) | ((b[i * 2 + 1] << 8) & 0xff00));
        }
        return s;
    }

AudioRecord还可以直接读short

int read (short[] audioData, int offsetInShorts, int sizeInShorts)

write code to check the platform endian:

Suppose we are on a 32-bit machine.

If it is little endian, the x in the memory will be something like:

   higher memory
      ----->
+----+----+----+----+
|0x01|0x00|0x00|0x00|
+----+----+----+----+
A
|

&x

so (char*)(*x) == 1

If it is big endian, it will be:

+----+----+----+----+
|0x00|0x00|0x00|0x01|
+----+----+----+----+
A
|

&x

so this one will be ‘0’.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值