美文网首页
Android short转换成byte

Android short转换成byte

作者: 空白Null | 来源:发表于2018-05-18 11:45 被阅读46次

    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];
        }

    相关文章

      网友评论

          本文标题:Android short转换成byte

          本文链接:https://www.haomeiwen.com/subject/dsfgdftx.html