字符串转字节

public static byte[] hexTobytes(String hex) {
byte[] bytes = new byte[hex.length() / 2];
for (int i = 0; i < hex.length(); i = i + 2) {
String subStr = hex.substring(i, i + 2);
int intH = Integer.parseInt(subStr,16);
byte b = (byte) intH;
bytes[i / 2] = b;
}
return bytes;
}

发布了33 篇原创文章 · 获赞 0 · 访问量 233

猜你喜欢

转载自blog.csdn.net/lemonmr/article/details/103060907