DIV and MOD ( was: Something IBM di

mcdonald at uxe.cso.uiuc.edu mcdonald at uxe.cso.uiuc.edu
Wed Nov 9 07:48:00 AEST 1988



>      -1 >> 1   giving  -1

Odd. Lets see here. In binary  4 bits       1 == 0001b
                                            0 == 0000b

                                           -1 == 1110b
        with zero filling shift    -1 >> 1    == 0111b  == 7
  with sign filling shift          -1 >> 1    == 1111b  == -0

neither of which are == -1. Perhaps you are unfamiliar with this
relatively common method. On some machines -1 >> 1 == -1, but not
all machines - and not necessarily in ANSI C.


:-)   :-)   :-)



More information about the Comp.lang.c mailing list