What you should know:
In the previous lesson, we were talking about the behavior of sequences of several bits. We showed that we were able to double the number of combinations that could be attained, just adding a bit to the left and repeating the same sequence twice, where the leftmost bit changes from 0 to 1.
So, if we start with just one bit:
One bit | |
0 | Always start from 0 |
1 | And then 1 |
From one to two bits | |
00 | Repeat the previous pattern adding a 0 to the left |
01 | |
10 | Change the leftmost bit to 1 while the rightmost bit repeats the pattern of the two previous rows. |
11 |
Usually the zeroes located in the leftmost part of the combination can be omitted, so that 01 can be considered equivalent to 1 and 00 to just 0.
Using the same algorithm we can easily write the combinations of any number of bits.
Combinations of 4 bits | |
0 | 0 |
1 | 1 |
10 | 2 |
11 | 3 |
100 | 4 |
101 | 5 |
110 | 6 |
111 | 7 |
1000 | 8 |
1001 | 9 |
1010 | 10 |
1011 | 11 |
1100 | 12 |
1101 | 13 |
1110 | 14 |
1111 | 15 |
First two combinations adding the fifth bit | |
10000 | 16 |
10001 | 17 |
Writing the combinations in the right order we can associate each sequence of bits with an integer number. Some of the combinations in the previous table have a specific property: the leftmost bit equals 1, while all the other bits are 0. These sequences are associated with a power of two, starting from 2^0=1.
Sequences with just a 1 in the leftmost position | ||
1 | 1 | 2^0=1 |
10 | 2 | 2^1=2 |
100 | 4 | 2^2=4 |
1000 | 8 | 2^3=8 |
10000 | 16 | 2^4=16 |
If more than one bit equals one, the value of the associated integer can be calculated by adding the value of every bit in the sequence, that does not equal 0. For example, the value of 1100, can be calculated, in binary and in decimal notation, as follows:
1000+100=1100 \Rightarrow 8+4=12In the same way, the value of 1110 can be calculated as follows:
1000+100+10=1110 \Rightarrow 8+4+2=14The value associated to any bit in the sequence doubles of halves if it’s moved one position to the left or to the right. For this reason dividing or multiplying by two in binary is as easy as removing or one bit from the right or adding a 0 in the same position.
For instance if we want to multiply 1100 by two, we can write:
1100 \cdot 10 = 1000\cdot10+100\cdot10= 10000+1000=11000In decimal numbers the same could be written as:
12\cdot2 = 8\cdot2+4\cdot2=16+8=24This also means that a number ending with a zero on the right is even, while a number ending with a 1 is odd.
More resources: