Byte转hex
要将Byte转换为hex,可以使用以下方式:
- 使用Java的Integer.toHexString方法:
byte b = 10;
String hex = Integer.toHexString(b & 0xFF);
System.out.println(hex);
- 使用Apache Commons Codec库的Hex类:
import org.apache.commons.codec.binary.Hex;
byte b = 10;
String hex = Hex.encodeHexString(new byte[]{b});
System.out.println(hex);
- 使用Java的String.format方法:
byte b = 10;
String hex = String.format("%02X", b);
System.out.println(hex);
以上方法中,byte b表示要转换的Byte值,hex为转换后的hex值。
原文地址: https://www.cveoy.top/t/topic/izOA 著作权归作者所有。请勿转载和采集!