GPC FAQ bug (shr)
f.couperin at online.fr
Mon Jul 17 17:09:45 CEST 2000
I discovered a small bug in GPC FAQ (Reference : shr) :
It give as an example : "a:= -127 shr 4; (* yields -7 *)" which is
false, it yields -8 !
I think we have to take care when manipulating bits of negative
A ShortInt with value-1 is coded 11111111b ! (-2 is 11111110b, -3 is
11111101b and so on)
If the last bit is 1 (that means the number is negative), the 'shr'
operator replaces the right new bits by 1.
Examples (Considering ShortInt type (8 bits)) :
-127 (coded 10000001b) shr 4 yields -8 (coded 11111000b)
-1 (coded 11111111b) shr 1 yields -1 !
More information about the Gpc