输出16进制byte数据的java实现
2018-06-05 本文已影响0人
未丑
在byte数据流的应用场景中,很多时候需要输出log,以便查看是否正确。
可以使用以下方法实现:
public void printHexString(String s, byte[] b)
{
System.out.print(s);
for (int i = 0; i < b.length; i++)
{
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1)
{
hex = '0' + hex;
}
System.out.print(hex.toUpperCase() + " ");
}
}