byte array to short array and back again in java

后端 未结 6 1620
时光取名叫无心
时光取名叫无心 2020-11-27 03:50

I\'m having some issues taking audio data stored in a byte array, converting it to a big-endian short array, encoding it, then changing it back into a byte array. Here is wh

6条回答
  •  悲&欢浪女
    2020-11-27 04:30

    public short bytesToShort(byte[] bytes) {
         return ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getShort();
    }
    public byte[] shortToBytes(short value) {
        return ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(value).array();
    }
    

提交回复
热议问题