base64转16进制
物联网开发中,通过nb-iot发布过来的数据很多都是base64的数据,我们需要进行转换16进制后续转换10进制加以显示。以下提供base64转16进制方法。代码如下:
原数据:
/4YAAAAFAAB1fDAwMDB8AAAAAAAAAAAAAAB8AAAAAAAAAAAAAHwAAAAAAAAAAAAAfAHzfAB8AAAAAHwAAA==
private static final char[] DIGITS
= {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
public static final String toHex(byte[] data) {
final StringBuffer sb = new StringBuffer(data.length * 2);
for (int i = 0; i < data.length; i++) {
sb.append(DIGITS[(data[i] >>> 4) & 0x0F]);
sb.append(DIGITS[data[i] & 0x0F]);
}
return sb.toString();
}
通过方法转换后:
ff86000000050000757c303030307c00000000000000000000007c000000000000000000007c000000000000000000007c01f37c007c000000007c0000