posted 23 years ago
Gayathri,
To answer your question if we shift any integer to the left once we actually double the number. Your example answers are both wrong! The answer we would expect is -10.
Here's why:
-5: 0xFFFFFFFB
1111 1111 1111 1111 1111 1111 1111 1011
<< 1: (add one zero to right side) FFFFFFF6
1111 1111 1111 1111 1111 1111 1111 0110
The final result is -10. For negatives it is easier to see value by taking twos complement and just add negative sign:
~: 0000 0000 0000 0000 0000 0000 0000 1001
+1: 0000 0000 0000 0000 0000 0000 0000 1010
0xA = 10 decimal.
Whoa,
Manfred.
[This message has been edited by Manfred Leonhardt (edited January 19, 2001).]