Byte, hexadecimal, binary

Byte represents 8 bits

Hexadecimal, binary four representatives

Therefore, using two bytes to represent the hexadecimal range in java byte is -128 to 127

The Byte to Hex

 public String bytesToHexString(byte[] bArr) {
        StringBuffer sb = new StringBuffer(bArr.length);
        String sTmp;

        for (int i = 0; i < bArr.length; i++) {
            sTmp = Integer.toHexString(0xFF & bArr[i]);
            if (sTmp.length() < 2){
                sb.append(0);
            }
            sb.append(sTmp.toUpperCase());
        }
        return sb.toString();
    }

Guess you like

Origin www.cnblogs.com/guyuedashu/p/12077878.html