Davita
Davita

Reputation: 9114

How to force BinaryReader to read this array correctly?

I have a byte array, received from java application via network. I need to parse this array correctly. The format is as follow:

int - first for bytes
int - next for bytes
string - rest of data.

Take a look at this screenshot.
As you can see, the first four bytes is 0, 0, 0, 1. The actual integer value should be 1, but when I read it through BinaryReader.ReadInt32, I receive 16777216. I doubt this has something to do with byte endianness (but could be wrong), but I don't know how to fix it.

Any help would be appreciated.

Thanks

Upvotes: 0

Views: 319

Answers (1)

Yes, that's an endian issue. This question has examples of how to reverse the byte-order of integer types

Upvotes: 2

Related Questions