Hi all, i have this string in HEX: 00024944554E49563130434800A0 and need to convert in ASCII.
I have tried to use the following solution, but the encoding of the last parte of the string is incorrect "00A0" after the conversion in ASCII (and converted again to be sure of the date transmitted) became "003F", probably is an Encode problem, but i dont know how and where use it with success.
public static string HextoAscii(string HexString)
{
string asciiString = "";
for (int i = 0; i < HexString.Length; i += 2)
{
if (HexString.Length >= i + 2)
{
String hs = HexString.Substring(i, 2);
asciiString = asciiString + System.Convert.ToChar(System.Convert.ToUInt32(HexString.Substring(i, 2), 16)).ToString();
}
}
return asciiString;
}
Thank you very much for your help :)

Samuele RossiPosted Sep 24, 2014, 9:34 AM
VulpesPosted Sep 24, 2014, 9:28 AM
Could it perhaps be a checksum for the rest of the string?
Samuele RossiPosted Sep 24, 2014, 8:00 AM
Anyway i did a first conversion from ASCII to Hex using Encode.Unicode and worked good (i got all the values expected). One of the value was this 00A0 that i need to gove back as Echo of the file.
The problem that i have is to convert it back.
VulpesPosted Sep 24, 2014, 7:09 AM
I don't recognize 00 02 as a byte order mark so I wondered whether it was coming from a serial port device rather than a file?
02 (or STX) means 'start of text' in some old transmission protocols.
Assuming it was encoded in ASCII in the first place, the only printable characters are:
IDUNIV10CH
which might make some sense.
There are, of course, many single byte 'extended ASCII' encodings where A0 might mean something. For example in Windows 1252 it means 'non-breaking space'.