Android short转换成byte

2018-05-18  本文已影响46人  空白Null

Android Java处理两个字节的short转换成byte并放在byte[]

ByteBuffer bbuf = ByteBuffer.allocate(2);
    bbuf.putShort(value);
    byte[] data = bbuf.array();
    ArrayList<Byte> al = new ArrayList<>();
    for (int i = data.length - 1; i >= 0; i--) {
        al.add(data[i]);
    }
    byte[] buffer = new byte[al.size()];
    for (int i = 0; i <= buffer.length - 1; i++) {
        buffer[i] = al.get(i);
    }
    byte[] buffer1 = new byte[2];
    int bufIndex = 0;
    for (int i = 0; i < buffer.length; i++) {
        buffer1[bufIndex++] = buffer[i];
    }
上一篇下一篇

猜你喜欢

热点阅读