16进制字符串的相关转换

public static byte uniteBytes(byte src0, byte src1) {
byte _b0 = Byte.decode("0x" + new String(new byte[] { src0 }))
.byteValue();
_b0 = (byte) (_b0 << 4);
byte _b1 = Byte.decode("0x" + new String(new byte[] { src1 }))
.byteValue();
byte ret = (byte) (_b0 ^ _b1);
return ret;
}

public static byte[] HexString2Bytes(String src) {
byte[] ret = new byte[8];
byte[] tmp = src.getBytes();
for (int i = 0; i < 8; i++) {
ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
}
return ret;
}

public static int byte2int(byte[] res) {
// 一个byte数据左移24位变成0x??000000,再右移8位变成0x00??0000
int targets = (res[0] & 0xff) | ((res[1] << 8) & 0xff00) // | 表示安位或
| ((res[2] << 24) >>> 8) | (res[3] << 24);
return targets;
}

/*private Integer hexToInt(String str, int start, int end){
long res = 0;
for(int i = start; i < end; i++){
res = res*16 + Integer.parseInt(str.substring(i,i+1), 16);
}
return res;
}*/

原文地址:https://www.cnblogs.com/Miami/p/4583232.html