(no subject)

Feb 04, 2010 11:55

Noticing this weird behavior with a bit shift right, like 10100000 >> 2 would be 11101000.

Eventually realized it was related to using a regular (signed) char type, behaves normally with unsigned.

So I found in the comp.lang.c faq that the shift right on a signed type varies by implementation but is usually equivalent to integer divide by two, which I suppose holds true until you get to -1 and then it stuck there at 11111111 (does not shift to zero).

It's also inconsistent with the bit shift left behavior, the sign bit just shifts right (left) off the map with << 1.

So, everything that ever was written in C is now pure crap, into the discard. Take that Billybob Khernigan.
Previous post Next post
Up