At 8:28 AM -0800 2000/02/17, Danny Epstein wrote:
>At 7:57 AM +0100 2/17/00, Aaron Ardiri wrote:
> > a shift right ">>" works the way you intend if the number is
> > unsigned.. however, if you have a negative number, the shifting
> > works slightly different.
> >
> > -32 >> 1 should give you -16 right? and what does this tell
> > you just by looking at it? *the* SIGN bit is maintained, and
> > hence the MSB is not removed :>
>
>I don't think you can rely on the behavior of >> on signed integers in C.
Correct. The >> operator may or may not perform sign extension on signed integers. No
guarantees, so use it only with unsigned integers or positive signed integers.
BTW, K&R sez: "The value of E1 >> E2 is E1 right-shifted E2 bit positions. The right
shift is guaranteed to be logical (0-fill) if E1 is unsigned; otherwise it may be (and
is, on the PDP-11) arithmetic (fill by a copy of the sign bit)."
Heh heh... PDP-11... I feel so old now...
Regards,
Jim Schram
3Com/Palm Computing
Partner Engineering
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html