美文网首页
Byte数组变为int,int变为byte数组

Byte数组变为int,int变为byte数组

作者: 大旺旺的弟弟小旺旺 | 来源:发表于2022-04-05 14:07 被阅读0次
        public static void main(String[] args) {
            byte[] bytes1 = int2byte(200);
            for (int i = 0; i < bytes1.length; i++) {
                System.out.println(bytes1[i]);
            }
            System.out.println(byte2int(bytes1));
        }
    
        public static byte[] int2byte(int res) {
            byte[] targets = new byte[4];
            targets[0] = (byte) (res & 0xff);
            targets[1] = (byte) ((res >> 8) & 0xff);
            targets[2] = (byte) ((res >> 16) & 0xff);
            targets[3] = (byte) (res >>> 24);
            return targets;
        }
    
    

    相关文章

      网友评论

          本文标题:Byte数组变为int,int变为byte数组

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