Reputation: 1876
I'm attempting to handle endianness in a cross-platform C++11 application.
Suppose I'd like to convert a 64-bit value from big endian to little endian with well-defined behavior. One resource suggests I could load the big endian version into std::bitset
and reverse the contents.
But that isn't correct, is it? Endianness seems to always deal with byte order, not bit order, but I can't find a definitive resource that explicitly addresses the matter.
Upvotes: 1
Views: 175
Reputation:
You're absolutely right.
If endianness is shown by the representation of the value 0x12345678
, then big endian is 12 34 56 78
and little endian is 78 56 34 12
. Reversing the bits in the big endian representation would not produce the little endian representation, only reversing the bytes would.
Upvotes: 4