c# - byte array to string and back. Confused -


this question has answer here:

what wrong code? why differences?

byte [] data = new byte [] {0x21, 0x4b, 0x9b, 0xe1, 0x2d, 0xa7, 0x4b, 0x93, 0x1e, 0x3f, 0xda, 0x4f, 0xb1}; console.writeline(bitconverter.tostring(data));  string datastr = asciiencoding.ascii.getstring(data);        byte[] ca = asciiencoding.ascii.getbytes(datastr); console.writeline(bitconverter.tostring(ca)); 

output:

21-4b-9b-e1-2d-a7-4b-93-1e-3f-da-4f-b1

21-4b-3f-3f-2d-3f-4b-3f-1e-3f-3f-4f-3f

ascii doesn't define character codes above 7f, , seems asciiencoding.ascii.getstring() chooses replace invalid bytes 3f, represents character ?.

you might want read joel spolsky's excellent article on encoding.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -