SQLite Forum

Endianness help
In case anyone's wondering how I got embroiled in all this. Through a lengthy period of illness I've been trying to teach myself proper c & c++. I came across the bit array in c++ and thought I'd learn a lot by trying to create something similar in c. I wanted it to be such that I could insert and delete blocks of bits into the bit array (similar to a c++ vector) in an efficient way. Doing it on my little endian laptop was fairly easy if time consuming. The good thing about little endian was you could break into the byte array at any index with a uint64_t* and shift the u64 as a whole. Doing the same on a big endian machine is a lot less intuitive and requires shifting in opposite directions.

When I tried to code it so that it would work on a big endian machine then I hit the confusion and started freaking out about bit order, storing and reading from disc etc. Reading everything I searched just added to the confusion. Any questions on the subject on stack overflow were polluted with 'endianness doesn't apply to bits' soundbites but no one debunked the claim in the linux article, no one stated the bit pattern for a byte would be the same on disc regardless of the endianness, no one mentioned DRAM array structures. For that I thank you all and hope that I won't be the only one to learn something from this thread. Going by stack overflow I wasn't the only one asking these types of questions. "It will just work" doesn't do it for me.