Can you please explain the below lines, with some good examples.
A left arithmetic shift by n is
equivalent to multiplying by 2n
(provided the value does not
overflow).
And:
A right arithmetic
shift by n of a two’s complement value
is equivalent to dividing by 2n and
rounding toward negative infinity. If
the binary number is treated as ones’
complement, then the same right-shift
operation results in division by 2n
and rounding toward zero.
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.
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.