Reputation: 4609
I've been reading something about endianness, it applies to bytes not bits, but isn't everything in the end a group of bits?
Now I also read that we refer to bytes not bits because computers are byte-addressable and can get a byte of data at a time, and endianness will refer to where the least significant "byte" is, agreed.
But then, how are the bits stored in these individual bytes?.I mean should't that matter where is my least significant bit?, I've always been comfortable with the least significant bit at the right, so is it that so at hardware level as well?
If I want to access particular bits in my byte, how will addressing work with bits?, that is my question
To make it more clear, the lowest address will be for the most significant "bit" or the least significant "bit"
Upvotes: 1
Views: 326
Reputation: 1
The MAC address for Token Ring and Ethernet have different bit-wise endian representation.
A MAC addressing byte for Token Ring (0x34) = MAC addressing byte for Ethernet (0x2C). The address order of bytes is still big-endian, but bits within a byte have different bit-endian. This makes a compatibility issue when using systems with both types of interfaces for network traffic.
Upvotes: 0
Reputation: 4809
Accessing bits is generally done by masking and shifting. For the mask itself you don't need to consider the position of the most/least significant bit. Bit 1 has mask 1, bit 2 has mask 2, bit 3 has mask 4, etc.
If you want bit n
in the position of the least/most significant bit on arbitrary hardware and arbitrary bits-per-byte settings, then there's only one algorithm:
/* set bit N */
extr <- 2^N
do
extr <- rot_right(extr)
until (extr & 1)
This algorithm will also work if the least significant bit is internally stored left-most, but it requires a bit-rotate operation. You can then work out if the LSB is leftmost or rightmost by using a counter.
In general (these days) it is safe to assume though, that the least significant bit is the rightmost in a byte.
Upvotes: 0