我正在尝试将字符串转换为具有 2 个不同字节的字节数组。
例如: String s1 = "055E"
我需要将其转换为类似
byte b1 = Integer.parseInt(05,16); - 1byte
byte b2 = Integer.parseInt(5E,16); - 1byte
最后我需要一个字节数组,其中包含值b1,b2。
byte[] b = {b1, b2};
对此的任何帮助将不胜感激。 提前致谢
最佳答案
试试这个:
String s1 = " 055E";
s1 = s1.trim();
byte[] b = {
(byte) Integer.parseInt(s1.substring(0, 2), 16),
(byte) Integer.parseInt(s1,substring(2), 16)
}
关于java - 字符串到字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11235914/