How do I convert a set of hexadecimal bytes to a custom string
So basically I need to find a way to convert this; 29 38 33 30 3D 34 FF, to this; Zidane
FF being character to imply end of name.
What I've got so far is that I can read that to its literal string, )830=4ÿ, which isn't 开发者_运维百科at all user friendly for what I'm trying to create.
Now just by that one name alone you can guess what I'm working on, but this is the only thing I seem to be getting stuck on is the whole custom character string.
This is the code to get string from hex string,
private string HexString2Ascii(string hexString)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= hexString.Length - 2; i += 2)
{
sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
}
return sb.ToString();
}
Will be happy if you explain in what format is the input string, hex or byte array.
Ah I see what is happening. Remember that when using Hex you have Unicode, Shift JIs and in your case Little-endian. As I understand it looks like you have an incorrect hex table for what you are currently trying to read. Sorry if my answer didn't help enough.
If you decode the hex values and expect the output to be ascii encoded then you get exactly what you state above, as seen using this online hex decoder.
The string is not obviously ascii encoded. I cant be certain of the exact encoding but by looking at the values, the expected output and the difference between the values you can predict how to map values to letters:
A-Z = 0x04 - 0x29
EG: 'A' = 04, 'B' = 05, .... 'Z' = 29
a-z = 0x30 - 0x55
EG: 'a' = 30, 'b' = 31, .... 'z' = 55
This should be enough to get you a readable string.
精彩评论