user2144480
user2144480

Reputation: 1097

BitConverter is using Big when it should use little endian

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

Answers (1)

D Stanley
D Stanley

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

Related Questions