[英]how to convert from decimal to ASCII characters
Im trying to write a function that will convert the last two Hex in a string to ASCII characters. 我试图编写一个函数,将字符串中的最后两个十六进制转换为ASCII字符。 like "ab3A" should print "ab:"
如“ ab3A”应打印“ ab:”
this is the code i wrote, it converts the last two to decimal but its unable to convert that decimal to ASCII characters. 这是我编写的代码,它将后两位转换为十进制,但无法将十进制转换为ASCII字符。 i tried to use .toString() to accomplish it, but no success.
我试图使用.toString()来完成它,但是没有成功。
private static String unmangle(String word)
{
String newTemp = word.substring(word.indexOf('%')+1);
int hex = hexToInt(newTemp);
String strI = Integer.toString(hex);
System.out.println(strI);
word=word.replace("%", "");
word=word.replace("+", " ");
return word = word.replace(newTemp, "")+ strI;
}
You are very close: all you need is a cast instead of a call of Integer.toString
- 您非常接近:您所需
Integer.toString
的只是Integer.toString
而不是调用Integer.toString
private static String unmangle(String word)
{
String newTemp = word.substring(word.indexOf('%')+1);
char hex = (char)hexToInt(newTemp);
word=word.replace("%", "");
word=word.replace("+", " ");
return word = word.replace(newTemp, "")+ hex;
}
First you should know how to make Hex to ASCII. 首先,您应该知道如何将十六进制转换为ASCII。
String newTemp=word.substring(word.length-1,word.length);
char a=newTemp.substring(0,0);
char b=newTemp.substring(1,1);
int c=0,d=0;
//And you should convert to int.
if(a='A'|'a')
c=10;//the same to d.
//and
c=c*16+d;
String strI = Integer.toString(c);
return word.substring(0,word.length-2)+strI;
I am so sorry my English is not well. 对不起,我的英语不好。 And this is my way to deal with this question.String
strI = Integer.toString(hex);
这就是我解决这个问题的方法
strI = Integer.toString(hex);
this sentence is wrong.It makes hex to string.For example if hex=97,StrI="97" not "a" 这句话是错误的。它使十六进制成为字符串。例如,如果hex = 97,StrI =“ 97”而不是“ a”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.