int轉byte[],byte[]轉int

 public byte[] intToByte(int i) {spa

        byte[] abyte0 = new byte[4];orm

        abyte0[0] = (byte) (0xff & i);it

        abyte0[1] = (byte) ((0xff00 & i) >> 8);im

        abyte0[2] = (byte) ((0xff0000 & i) >> 16);margin

        abyte0[3] = (byte) ((0xff000000 & i) >> 24);static

        return abyte0;top

    }di

    public  static int bytesToInt(byte[] bytes) {co

        int addr = bytes[0] & 0xFF;new

        addr |= ((bytes[1] << 8) & 0xFF00);

        addr |= ((bytes[2] << 16) & 0xFF0000);

        addr |= ((bytes[3] << 24) & 0xFF000000);

        return addr;

    }

相關文章
相關標籤/搜索