Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does endianness apply to bit order too?

Tags:

c

endianness

I haven't found a specific question here on SO, if this is a duplicate please point it out to me and I'll delete this.

So really, does endianness have anything to do with bit order?

This seems to imply the answer is NO, while other sources (I fail to find one right now, but surely I've read some time ago some articles) imply that endianness is the order of bytes and bits.

To be more specific: in a Big Endian architecture, where MSB is first, inside any byte, is also MSb first? Conversly, on Little Endian systems, where LSB is first, is LSb also first?

LAST EDIT: I found this which says "Bit order usually follows the same endianness as the byte order for a given computer system"

like image 426
Bogdan Alexandru Avatar asked Aug 20 '14 10:08

Bogdan Alexandru


Video Answer


2 Answers

The other responses are not completely accurate. Yes, memory is byte addressable, so usually endianness stops there. But addressability isn't the only way to create well defined endianness.

In C, you can define bit fields. Bit fields have particular layouts; for example, the first bit field, if one bit, could be stored in either the msb or the lsb, and wrapping bit fields across byte boundaries in a big endian way is strikingly different than doing so in a little endian way. So if you define bit fields, you may have bit endianness.

But how these are arranged would have more to do with the compiler than the architecture, at least as a rule.

like image 92
H Walters Avatar answered Sep 21 '22 06:09

H Walters


Looking back at this question I asked some years ago, today I can add a partial response with an example where bit endianness exists and is important: in communication protocols. Any protocol specification needs to define which bit is sent first when an octet is pushed in a bit stream.

like image 40
Bogdan Alexandru Avatar answered Sep 21 '22 06:09

Bogdan Alexandru