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

2022-04-05  本文已影响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;
    }

上一篇 下一篇

猜你喜欢

热点阅读