This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
right shift : strange behavior
- From: Manish Baphna <manish_baphna at yahoo dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 26 Jul 2007 23:35:01 -0700 (PDT)
- Subject: 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