Reputation: 1097
I have a file I'm reading two bytes from. (03, 0E). I use the binary reader to get my bytes
reader.ReadBytes( 2 ), 0 )//[0] = 03 and [1] = 0E
then I convert with
BitConverter.ToInt16( reader.ReadBytes( 2 ), 0 )
the convert has little endian set to true, so correct me if I'm wrong but that means 0x03 then 0x0E and my result should be 782 in decimal but its showing as 3587. I checked the immediate window and its the converter that is swapping. I'm missing something here certainly but I don't know what?
Upvotes: 0
Views: 1458
Reputation: 152521
You have it backwards. From the documentation:
"Big-endian" means the most significant byte is on the left end of a word. "Little-endian" means the most significant byte is on the right end of a word.
So reading {03},{0E}
in a little-endian system means that 0E
is the most significant byte, so when read into a 2-byte structure it represents 0E03
in hex, or 3,587 in decimal.
Upvotes: 3