[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bit-position of rightmost 1
- To: PRATT at MIT-MC
- Subject: Bit-position of rightmost 1
- From: JONL at MIT-MC (Jon L White)
- Date: Fri, 24 Nov 78 17:20:00 GMT
- Cc: (BUG LISP) at MIT-MC
- Original-date: 24 NOV 1978 1220-EST
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