[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bit-position of rightmost 1



For a 2's complement machine, the following expression will
give the index, 0-origin, of the rightmost 1, which is the same
as the exponent for the highest power of 2 that evenly divides
the number:
   (1- (HAULONG (BOOLE 1 N -N)))      for 0 < N < bignum
Where the base of the arithmetic is suspect, one may build-in the
feature of 2's complement that makes this work:
  (1- (HAULONG (BOOLE 1 N (BOOLE 6 (1- N) 77777777777)
                                      for 0 < N < 77777777777