What is meant by adding a column in bits?
I am not able to understand what is meant by the following text, which I referred from a book:
Consider the four two-bit numbers
00
,01
,10
,11
. If you add up the one’s bit, you get an even number. Likewise, if you add up two’s bit, you get an even number. No matter how many bits in the number, if you add up a column, you get an even number.
Specifically, what is meant by "add up one's b开发者_StackOverflow中文版it" for 00
?
They just mean that if you write the four numbers in a column:
00
01
10
11
...and you look at how many bits in the first column (the "one's bits") are 1, you get an even number. Similarly for the second column (the "two's bits").
Their claim is that no matter how many bits the number has, if you write down all numbers with that many bits, the number of 1's in each column will be even.
Their claim is false for one-bit numbers. In general, for n bits, the number of 1s in each column will (obviously) be 2^(n-1), which is even except when n=1.
What book is this? What point are they trying to make?
The bits in a binary number are generally "named" column-wise according to their respective power of two:
00000000
│││││││└── 1's bit
││││││└─── 2's bit
│││││└──── 4's bit
││││└───── 8's bit
│││└────── 16's bit
││└─────── 32's bit
│└──────── 64's bit
└───────── 128's bit
The "one's" bit is the bit that represents a "one", i.e. the rightmost bit. The "two's" bit is the bit used to hold a 2, i.e. the bit second to the right. The next bit to the left of the "two's" bit is the "four", etc.
001 = 1
010 = 2
100 = 4
Thinking back to the way numbers in decimal numbers. For example: 184. Starting at the right-most number, we have 4, it's equivilent to saying "there are 4 ones in this numbers." It's in the ones place, as we progress left we have the 8 in the tens place (meaning to represent that there are 8 tens) and 1 in the hundreds place (only 1 hundred). For a binary number like 10 (binary for 2), the 0 in the right-most place is in the ones place, that "column" (position from the right hand side) is the place that denotes how many 1's are in that number. Along the same lines, the 1 is in the twos place, denoting how many twos are in this number.
i think what it is trying to say is that if you take all the numbers with a certain number of bits - in this example, 2 then add the values of each column, the result will be even.
so, for the 4 2 bit numbers, add each column separately:
0 0
0 1
1 0
+1 +1
- -
2 2
each column adds to 2 - an even number
similarly, for all the 3 bit numbers:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
+1 +1 +1
- - -
4 4 4
each column adds to 4 - even
精彩评论