I am a little confused...

The following happened:

I opened some TGA-images and read them DWORD by DWORD; no problem everything is fine.
When i open some binary files i made myself with a hex-editor the DWORDs are screwed up. Meaning the content of the DWORDs is mirrored. So now when i convert inside my hex-editor the files from little endian to big endian format on DWORD boundaries everything is fine again. I first thought I did something wrong when creating the file so i tried different hex-editors with different configurations but the same result.
Now, am i plain stupid or what is the problem here?

I am in a DOS environment, if that is important.
Posted on 2008-03-04 11:22:27 by atcl
This sounds like a simple human error is staying in your code. Did you forget to bswap when saving? Did you bswap actually twice?
Posted on 2008-03-04 13:42:50 by Ultrano
It's hard to tell what the problem is without any code but remember that the byte order of a DWORD is generally reversed when you look at it with a hex editor. This is because a hex editor will display BYTE data in the exact order it finds it so it will look like this...


is actually stored as

0xCC 0xDD 0xEE 0xFF

and will appear that way when you view it with a hex editor.

If you dump a memory buffer to a file (BIN) then all the data will be exactly in the same order at load time, DWORDs will still be read properly and BYTE data as well, this is because you are sequentially storing bytes of data regardless of the "ENDIAN" ordering and unless you process the data on the way to the file you will not affect it and "ENDIAN" order is insignificant.

Posted on 2008-03-04 14:05:46 by donkey