2015-04-20 40 views
1

如何将十六进制字符串值转换为字节。例如,我打通了十六进制字符串值 -十六进制字符串值为0x字节

String strVal = String.format("%02x", buf[i]); //lets say it is "3D" 

现在我想将其转换成字节,这样我就可以做这样的事情

byte bVal = 0x[value?] //0x3D; 

感谢

+0

你看过commons-codec吗?这将为你照顾它。 – Dan

回答

0
String hex = ...; 
int temp = Integer.parseInt(hex , 16); 

byte result = (byte) temp; 
0

你可以使用getBytes()。所以strVal.getBytes()。

相关问题