I am trying to convert byte array to string but bytes are not being converted to string correctly.
byte[] testByte = new byte[]
{
2, 200
};
string string1 = Encoding.ASCII.GetString(testByte);
byte[] byte1 = Encoding.ASCII.GetBytes(string1);
string1 is giving value as \u0002? and byte1 is not getting converted back to 2 and 200. I tried with UTF8 but that is also giving same problem.
I have been given 256 array of chars and integer values. I need to write these values on media as string and read back as bytes. I need conversion to write and read byte data. I am facing problems when integer value comes more then 127.
What should I do so I get original byte values from string?
Encoding.ASCIIconverts any values higher than that to?marks. That's why 200 isn't being encoded/decoded correctly.200by itself isn't a valid UTF8 character - non-ASCII characters have to be encoded as 2 or more bytes - so you get the same result.)