right shift : strange behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All, 

I am not able to get convinsing/authorising
explanation for this right shift problem...it goes
like this

(A)    ~0x0  = 0xFFFFFFFF  // this is straight forward

(B)    (~0x0>>5 ) = ( 0xFFFFFFFF >>5)   // right  
                         //shifting by 5 bits  both 
                        // 'left and right hand sides'
                          
But seems (B) is INCORRECT statement seeing the print
!

int number ;

number = ( 0xFFFFFFFF >> 5 ) ;
cout << hex << number << endl ;

number = ( ~0x0 >> 5 ) ;
cout << hex << number << endl ;
--------
output >> 7ffffff
         ffffffff


What's the rule followed above ? 
This behavior is same on SPARC/ Linux/ Windows.


Does that imply that '~' will always return a signed
value and hence this behavior ?

Thanx in Advance :)
-Manish


       
____________________________________________________________________________________
Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 
http://tv.yahoo.com/collections/222

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux