'INT16 - Big Endian (AB) convert to hex and ascii
I want to convert hex and ascii from INT16 - Big Endian (AB) data type. But I don't know how to continue. I want to do similar work in extension. I want to get character from first int singned or unsingned data type.
example :The Modbus pool program can do this.
display-> hex select
convert to ascii and hex
Solution 1:[1]
I'm solved
int Int16Values=568;
string hexString=Int16Values.ToString("X4");
try
{
string ascii = string.Empty;
for (int i = 0; i < hexString.Length; i += 2)
{
string hs = string.Empty;
hs = hexString.Substring(i, 2);
ulong decval = Convert.ToUInt64(hs, 16);
long deccc = Convert.ToInt64(hs, 16);
char character = Convert.ToChar(deccc);
ascii += character;
}
return ascii;
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
Console.WriteLine(ascii);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alpovo |