# Why does bitRead() start at the rightmost bit?

Good afternoon,

Lately, I was wondering why bitRead() starts at the rightmost bit.***
Every student/programmer knows that array indices start at 0 which is the leftmost bit.
Say, you want to declare a character array emoji, you would write it from left to right.
Then most likely you would want your program to read the bits from left to right.

***I am confident that there is a good explanation for this, I just can't figure it out.

Thank you.

3,456 what is the smallest digit?

1101101 same thing.

-jim lee

I am trying to boil down my question.
A byte is an array of 8 bits.
Array indices start at 0, which is the leftmost bit.
Why does bitRead() start at the rightmost bit?

There must be an easy explanation for this, I just can't figure it out.

Array indices start at 0, which is the leftmost bit.

Array indices are numbers, not bits. I wonder if you are referring to the first element in an array when it is initialised.

``````int myArray[4] = { 5, 6, 7, 8 };
``````

Where the left most value is element 0 in the array.

When I got into computing, bit 0 was the LSB. Later on in my career, I saw documents that defined bit 0 as the MSB, which didn't make much sense to me.

I was wondering why bitRead() starts at the rightmost bit

A byte is an array of 8 bits.

Wrong. A byte has 8 bits but it is not an array

Here is a decimal number 1234
It has 4 digits, thousands, hundreds, tens and ones in that order
Highest significant digit on the left, least significant digit on the right

Here is a 4 digit binary number 1011
It has 4 digits, eights, fours, twos, and ones in that order
Highest significant digit on the left, least significant digit on the right

Would you suggest writing one thousand two hundred and thirty four as 4321 ?

The bitRead() reference page puts it like this

x: the number from which to read.
n: which bit to read, starting at 0 for the least-significant (rightmost) bit.

bitRead() reads the least significant bit with an index of zero and so on through the bits, right to left (least significant to most significant). You could, of course write your own function to read bits of a byte left to right but you would not get the correct answer

Try

``````bitValue = bitRead(byteValue, 7 - bitIndex);
``````

Finally I got it!

A byte is not an array of bits and therefore a bit is not part of an array. That was the easy explanation I was looking for. So, yes, thank you to all.
Hence, it is useless to compare a rightmost bit against what in an array is at index 0.

Since, I am a high school teacher, I need to think this over, because this will confuse folks.
My plan was to teach a byte as a list/array of bits. But, since it is not, I need to rethink the whole lesson plan.

Cool beans.

Array indices start at 0, which is the leftmost bit.

Array indexing doesn’t start “at the left”, either. That’s just one representation. I would say that the 0 index of the array is the “top” element in the array. But I’ve also seen the zero-th element at the bottom of a drawing of memory locations.

You might be able to think of it as being similar to the “arbitrariness” of mathematical coordinate systems…

But for bitRead(), 0 is the “rightmost” bit because that’s the bit with a place value of 20

(For the internals of the hardware, “right” and “left” have no relevance at all…)
The famous paper On Holy Wars and a Plea for Peace might be useful.

21za2323rzcvzxcv:
Finally I got it!

A byte is not an array of bits

I disagree. A byte isn't a representation of an integer, so the "leftmost" or "rightmost" bit has no significance. It's when its data is used to represent a binary integer, that the bit positions have any significance. The term "byte" is intentionally agnostic about the significance of the bits. In that sense, it is like an array of bits. And, the position number "bit x" is like an index.