??,Java?bin2hex
??????????????????java.util.zip.Deflater
?,???????????????????????
??????????,??????bin2hex
??????????????????:
import java.util.zip.Deflater; public class Bin2HexExample { public static void main(String[] args) { byte[] binaryData = https://www.yisu.com/ask/new byte[]{0x12, 0x34, 0x56, 0x78};"Hexadecimal representation: " + hexString); } public static String bin2hex(byte[] data) { Deflater deflater = new Deflater(); deflater.setInput(data); deflater.finish(); StringBuilder sb = new StringBuilder(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); for (int i = 0; i < count; i++) { sb.append(String.format("x", buffer[i])); } } deflater.end(); return sb.toString(); } }
??????,???????????????(0x12, 0x34, 0x56, 0x78)????????,????bin2hex
??????????????,???????????
??:bin2hex
?????Deflater
???????????,??????????????????????????????????????????,???????????????????????