Binary Left Shift <<
When shifting left, the most-significant bit is lost, and a 0 bit is inserted on the right end.
Left shift is equivalent to multiplying the bit pattern by 2k (if we are shifting k bits).
10 << 2 = 10 * 22 = 10 * 4 = 40 10 << 3 = 10 * 23 = 10 * 8 = 80 11 << 6 = 11 * 26 = 11 * 64 = 704 1 << 3 = 1 * 23 = 1 * 8 = 8 1 << 4 = 1 * 24 = 1 * 16 = 16 | 5 * 4 = 5 * 22 = 0101 * 22 = 010100 = 216 + 28 = 20 2 * 8 = 5 * 23 = 0010 * 23 = 010000 = 216 = 16 most-significant bit is lost |
Binary Right Shift >>
When shifting right, the less-significant bit is lost, and a 0 bit is inserted on the left end.
Right shift is equivalent to dividing the bit pattern by 2k (if we are shifting k bits).
10 >> 2 = 10 / 22 = 10 / 4 = 2 10 >> 3 = 10 / 23 = 10 / 8 = 1 11 >> 6 = 11 / 26 = 11 / 64 = 0 1 >> 3 = 1 / 23 = 1 / 8 = 0 1 >> 4 = 1 / 24 = 1 / 16 = 0 | 5 / 4 = 5 / 22 = 0101 / 22 = 000101 = 20 = 1 2 / 8 = 5 / 23 = 0010 / 23 = 000010 = 0= 0 Less Significant bit lost |