gpt4 book ai didi

android - 将十六进制字符串转换为字符串

转载 作者:行者123 更新时间:2023-11-30 02:37:24 27 4
gpt4 key购买 nike

嗨,我必须尝试多种方法将 Hex String 转换为 ASCII String 但没有成功。虽然以前我做过同样的事情,但现在我无法做到。

我的代码是

private static String hexToASCII(String hexValue)
{
StringBuilder output = new StringBuilder("");
for (int i = 0; i < hexValue.length(); i += 2)
{
String str = hexValue.substring(i, i + 2);
output.append((char) Integer.parseInt(str, 16));
}
return output.toString();
}

但它返回的是像 b��¡

这样的垃圾值

我的十六进制字符串是

  621c8002008a820101a10a8c0341c2009c0341c2008302010288008a0105

如果有人也遇到同样的问题并解决了,请帮助我。

谢谢....

最佳答案

试试这个

public class HextoAsscii {

public static void main(String args[])
{
String hex="621c8002008a820101a10a8c0341c2009c0341c2008302010288008a0105";
String str="";
str= hexToASCII(hex);

}
private static String hexToASCII(String hexValue)
{
StringBuilder output = new StringBuilder("");

for (int i = 0; i < hexValue.length(); i += 2)
{
if(i+2<=hexValue.length())
{
String str = hexValue.substring(i, i + 2);
output.append(Integer.parseInt(str, 16));
}
}
System.out.println(output.toString());
return output.toString();
}
}

关于android - 将十六进制字符串转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26275937/

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