I will explain what happens in a base that we're more familiar with: 10.
In base 10, let's say you have a number N=123. Now, you "shift" this number to the left k=3 positions, filling the emptied digits with 0. So you get X=123000.
Note that X = N * 10k.
The case with base 2 is analogous.
Example 1 (base 10) | Example 2 (base 2)
|
N = 123 | N = 110101 (53 in base 10)
k = 3 | k = 2 (in base 10)
N << k = 123000 | N << k = 11010100 (212 in base 10)
|
10^k = 1000 | 2^k = 100 (in base 2; 4 in base 10)
N * 10^k = 123000 | N * 2^k = 11010100 (53 * 4 = 212 in base 10)
|
The case with right shift is simply a mirror of the process, and is also analogous in base 10. For example, if I have 123456 in base 10, and I "shift" right 3 positions, I get 123. This is 123456 / 1000 (integer division), where 1000 = 103.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…