Author | Topic: shift operators |
shan unregistered |
posted January 26, 2000 10:36 AM
What is the value of -31>>>5>>5>>>5>>5>>>5>>5? shortest way to find the output?
|
maha anna bartender |
posted February 01, 2000 03:14 PM
Here is the way! -31>>>5>>5>>>5>>5>>>5>>5? 1. Total bits to be shifted = 30 (5+5+5+5+5) 2. Since it is negative value the higher bits surely will be 1's (i.e 0xff (Upperbyte) because 31 will be somewhere in the lowerbyte) 3. Since int has 32 bits and we have to shift 30 bits right and this is an UNSIGNED RIGHT SHIFT all 30 0's will be filled 4. so we have 0x00000003 00000000 00000000 00000000 00000011 5. the ans. is 3
|
| | |