String s = "-1";
System.out.println(bytes2hex01("-1".getBytes(StandardCharsets.UTF_8)));
10进制转换为16进制
public static String bytes2hex01(byte[] bytes) {
BigInteger bigInteger = new BigInteger(1, bytes);
return bigInteger.toString(16);
}
public static String bytes2hex02(byte[] bytes) {
StringBuilder sb = new StringBuilder();
String tmp = null;
for (byte b : bytes) {
tmp = Integer.toHexString(0xFF & b);
if (tmp.length() == 1)
{
tmp = "0" + tmp;
}
sb.append(tmp);
}
return sb.toString();
}
public static String bytes2hex03(byte[] bytes) {
final String HEX = "0123456789abcdef";
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
sb.append(HEX.charAt((b >> 4) & 0x0f));
sb.append(HEX.charAt(b & 0x0f));
}
return sb.toString();
}
16进制转化为10进制
public static void HexToTen() {
Integer.toHexString(200);
Integer.parseInt("8C", 16);
}