I have recently faced a problem .The problem is here.We know that if we represent a decimal number in binary and move left all the bits by one. The left most bit is lost! and at the rightmost, a zero is added.
The above bit operation actually produce a number that is result of multiplication of the given number and 2.
For example, $0001001101110010 ⇒ a = 4978(16 bit)$
---------------- << 1 (SHIFT LEFT the bits by one bit)
$0010011011100100 ⇒ 9956$
My question is that why it happens? Can anyone explain what the reason behind it?
Take a sample binary number,
0110 , its value in decimal is (from rightmost to leftmost)
0 * 2^0 +
1 * 2^1 +
1 * 2^2 +
0 * 2^3 = 6.
Now shift all digits 1 bit to the left.
1100
0 * 2^0 +
0 * 2^1 +
1 * 2^2 +
1 * 2^3 = 12.
What you are essentially doing is multiplying all the powers of two by another 2, when you shift the digits to the left. Hope this answers your question. When you shift all digits to the right then through the same logic you are dividing the number by two.