Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualHodgman

Posted 01 November 2012 - 10:19 PM

What effect would that have? Would >> only shift 7 bits and ignore the sign bit?

There's two kinds of right shift -- arithmetic and logical. The former fills in the gap created at the top by "sign extending" (basically copying the top bit), and the later fills the gap with 0's.
IIRC, in C++ it's implementation-defined as to which kind of shift will be performed -- someone correct me if I'm wrong, or if C++11 has defined this behaviour!
In my experience every compiler has chosen the same implementation-defined behaviours: shifting a signed integer has always been an arithmetic (sign extending) shift, while shifting an unsigned integer is a logical shift.

#1Hodgman

Posted 01 November 2012 - 10:16 PM

What effect would that have? Would >> only shift 7 bits and ignore the sign bit?

Theres two kinds of right shift -- arithmetic and logical. The former fills in the gap created at the top by "sign extending" (basically copying the top bit), and the later fills the gap with 0's.
IIRC, in C++ it's implementation defined as to which kind of shift will be performed -- someone correct me if I'm wrong, or if C++11 has defined this behaviour!
Anyway, in my experience, shifting a signed integer has always been an arithmetic (sign extending) shift, while shifting an unsigned integer is a logical shift.

PARTNERS