I am reading a file byte-by-byte.
Say for example i have this byte: 0x41 (0100 0001) represented in hex.
Now, I want the first three bits of this byte, i.e (010).
I can use bitwise logic to extract the first three bits, but my question is will the first three bits be independent of endianess of the machine.(i.e they can’t be 001)?
Thanks,
Another way to think of this is that endianness only applies when you can read the components of an item individually – since you can typically independently read from memory the individual bytes of a 32-bit int, if you want to interpret those bytes as a 32-bit int you need ot ensure that the endianess of the architecture is taken into consideration.
Normally you can’t read from memory the individual bits of a byte, so there really is no concept of ‘bit endianness’ as far as memory architecture is concerned (I’m sure there is at the hardware level, but not something you can see at the software level). A few areas where you might need to deal with (or at least be aware of) bit endianness:
the order that the compiler stores bits of a bit field is compiler dependent (and is not necessarily related to the endianess of the hardware platform – different compilers might order bit fields differently for the same platform – it’s possible that a compiler could be configured one way or the other using command line options, similar to the way
charmight be set to be signed or unsigned). However, C bit fields really have nothing to do with hardware addressing.some hardware architectures do allow you to address individual bits (the ARM Cortex M3 for example), so in this case you’d need to know how the architecture arranged for bits to be addressed if you were to use that feature.
if you’re sending bits over a serial link – the hardware interface will typically specify whether the most significant bit or least significant bit is ‘shifted’ out on the wire first.