Table lookups

John Kessenich jk at hpfelg.HP.COM
Tue Jun 28 04:37:33 AEST 1988


    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.



More information about the Comp.lang.c mailing list