View Single Post
Old 08-06-2003, 12:18 AM   #19 (permalink)
npa
Code Monkey
 
Join Date: Jul 2003
Location: canada
Posts: 82
npa is on a distinguished road
"i want to count the number of set-bits in an interger!":

(can't take credit for this one):
Code:
public final static int getBits(int i) {
        i = ((i & 0xaaaaaaaa) >> 1) + (i & 0x55555555);
        i = ((i & 0xcccccccc) >> 2) + (i & 0x33333333);
        i = ((i >> 4) + i) & 0x0f0f0f0f;

        i += i >> 8;
        i += i >> 16;

        return i & 0xff;
    }
__________________
direct entry file specification.
npa is offline   Reply With Quote