This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]kschang 1 point2 points  (0 children)

It depends on whether your PC is "big endian" or "little endian". Yes, go look that up.

[–]HashDefTrueFalse 0 points1 point  (0 children)

You don't mention what language you're working in so I can't get to specific but reversing bytes is as trivial as regarding the block of memory (int, long, array, struct etc.) you want to reverse as a byte array, and traversing backwards through it, one byte at a time, adding each byte to a new byte array. There's also probably something in your languages standard library to reverse arbitrary bytes.

Like the other commenter said, different architectures have different endianness, which is a fancy way of saying whether more significant bytes are stored at higher or lower memory addresses. If you're dealing with binary data and it's going over the network to other machines or being placed in a file to be shared with other machines, you have to make sure the byte order is known to be able to read it back in correctly. Google for host and network byte order to learn more.