• Advertisement
Sign in to follow this  

[C++] Bytes stored in reverse? [resolved]

This topic is 3575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to read some binary data from a file. In the file are four bytes: 00 00 DE 51 (in hex), corresponding to an integer with the value 56913. I read the file with ReadFile(...) in the windows.h library. My problem is that when I print it out it has a value of 51 DE 00 00! When I print this as an integer it is 1373503488 which is definitely wrong. So it seems to me that the bytes stored in the file are in the opposite order of how bytes are stored in memory. Does anyone know how I might fix this? Should I "flip" the order of the bytes that I read, or can I read the file differently? Thanks! [Edited by - MattHughes on May 7, 2008 11:02:18 AM]

Share this post


Link to post
Share on other sites
Advertisement
Big endian vs little endian...... Your file is in one format and your CPU is in the other. You need to reverse the order of the bytes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement