使用Apache的Hex类实现Hex(16进制字符串和)和字节数组的互转


包名称:org.apache.commons.codec.binary

类名称:org.apache.commons.codec.binary.Hex

1、字节数组(byte[])转为十六进制(Hex)字符串

public static String byte2hex(byte[] input) {
    return Hex.encodeHexString(input);
}

2、十六进制字符串(Hex)转字节数字(byte[])

public static byte[] hex2byte(String input) {
    return Hex.decodeHex(input.toCharArray());
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM