gpt4 book ai didi

java - 十六进制字符串值到 0x 字节

转载 作者:太空宇宙 更新时间:2023-11-04 13:56:39 26 4
gpt4 key购买 nike

如何将十六进制的字符串值转换为字节。例如我通过 -

获取十六进制字符串值
 String strVal = String.format("%02x", buf[i]); //lets say it is "3D"

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

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

谢谢

最佳答案

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

byte result = (byte) temp;

关于java - 十六进制字符串值到 0x 字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29751510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com