Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hp-sde!hpfcdc!hpfelg!jk From: jk@hpfelg.HP.COM (John Kessenich) Newsgroups: comp.lang.c Subject: Re: Table lookups Message-ID: <690009@hpfelg.HP.COM> Date: 27 Jun 88 18:37:33 GMT References: <1802@loral.UUCP> Organization: HP Elec. Design Div. -FtCollins Lines: 13 How about taking the log (base 2) of your number? Here is a (maybe too slow) way of doing this. t = bitvariable; i = -1; while (t) { t >>= 1; ++i; } It takes your number (bitvariable) and leaves log base 2 in i, assuming bitvariable contains exactly one on-bit.