Jump to content
  • Advertisement
Sign in to follow this  
MattHughes

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

This topic is 3794 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!