package com.wxy.Utils; public class HexTool { static public byte hexStrToByte(String hexbytein){ return (byte)Integer.parseInt(hexbytein,16); } public static byte [] Str2Hex(String hexStrIn){ int hexlen = hexStrIn.length()/2; byte [] result; result = new byte[hexlen]; for (int i = 0; i < hexlen; i++){ result[i]=hexStrToByte(hexStrIn.substring(i*2,i*2+2)); } return result; } public static String Hex2Str(byte[] hexByteIn){ int len = hexByteIn.length; String restult = new String(); for(int i =0;i<len;i++) { restult += String.format( "%02x",hexByteIn[i] ); } return restult; } public static void main(String[] args){ final String HEX_CODE = "1234567890ABCDEF"; byte [] retbyte; retbyte = Str2Hex(HEX_CODE); String teststr = Hex2Str(retbyte); System.out.println(teststr); } }
Java HEX字符串和byte[]互相转换
最新推荐文章于 2024-09-30 16:25:42 发布