如何解决从十六进制值转换为String
| 在我的程序中,我得到了六进制格式的字符串。我想将其转换为字符串。怎么做 ? 谢谢并恭祝安康。 帕尔瓦蒂解决方法
使用以下代码将十六进制转换为字符串
String hexadecimalnumber = \"00000011\";
BigInteger big = new BigInteger(hexadecimalnumber);
String requiredString = big.toString(16);
System.out.println(\"...data...\"+requiredString);
谢谢
迪帕克
, String hex = \"ff\";
hex = Integer.toString(Integer.parseInt(hex,16));
, class Test
{
private static int hextoint(char c) {
if (c >= \'0\' && c <= \'9\') {
return c - \'0\';
}
if (c >= \'a\' && c <= \'f\') {
return c - \'a\' + 10;
}
if (c >= \'A\' && c <= \'F\') {
return c - \'A\' + 10;
}
return -1;
}
private static String hexdec(String str) {
int len = str.length();
if(len % 2 != 0){
return null;
}
byte[] buf = new byte[len/2];
int size = 0;
for (int i = 0; i < len; i += 2) {
char c1 = str.charAt(i);
char c2 = str.charAt(i + 1);
int b = (hextoint(c1) << 4) + hextoint(c2);
buf[size++] = (byte)b;
}
return new String(buf,size);
}
public static void main(String[] args)
{
String str = \"616263\";
String out = hexdec(str);
System.out.println(out);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。