Unicode strings are 2 bytes, and for ASCII strings looks like
0x41, 0, 0x42, 0, 0x43, 0 ... // {ASCII code for A}, 0,...
So if you read bytes in opposite order (BigEndianUnicode
) you get nonsense characters. String above read as 0x4100, 0x4200, 0x4300 ...
instead of 0x0041,...
Similar happens when you start reading at odd offset (your seeking from end of file code) - bytes with ASCII text look like:
0, 0x41, 0, 0x42, 0, 0x43 ...
which are read as 0x4100, 0x4200, 0x4300...
ReadByte
takes out first 0 so you are reading from beginning of character, not the middle of it and sequence become valid ASCII-only Unicode string (with potentially invalid last character:
0x41, 0, 0x42, 0, 0x43,...