This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

right shift : strange behavior


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]