"

Thus, if A is 1010 and B is 1100, then

A & B = 1000

A | B = 1110

A ^ B = 0110

"]]>

""

If you use -march=native on a Nehalem or better with a recent gcc, it works fine:

]]>

rokicki@stoa:~$ cat bc.c

int f(int v) {

return __builtin_popcount(v) ;

}

rokicki@stoa:~$ gcc -O -march=native -S bc.c

rokicki@stoa:~$ cat bc.s

.file "bc.c"

.text

.globl f

.type f, @function

f:

.LFB0:

.cfi_startproc

popcntl %edi, %eax

ret

.cfi_endproc

.LFE0:

.size f, .-f

.ident "GCC: (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2"

.section .note.GNU-stack,"",@progbits

Many thanks.]]>

00010101

00010100

00010001

00010000

00000101

00000100

00000001

00000000

What we want is a way to get the next element in this list in O(1).]]>

Finding the lowest set bit turns out to be surprisingly easy, with the right combination of bitwise and arithmetic operators. Suppose we wish to find the lowest set bit of x (which is known to be non-zero). If we subtract 1 from x then this bit is cleared, but all the other one bits in x remain set. Thus, x & ~(x - 1) consists of only the lowest set bit of x. However, this only tells us the bit value, not the index of the bit."

If we take the lg of that value will we get the index?]]>

All subsets of 7 will be 00000111 to 00000000 i guess.

But what we are trying to solve above?]]>

]]>intdif(inta,intb) // returns the number of different places {intnum = 0;while(a>0 || b>0) {if(((a%10)^(b%10))!=0) { num++; } a/=10; b/=10; }returnnum; }

I tried to use xor to state that 2 numbers differ by one digit

like :

1907654321 , 907654321

but didnt work

I want somehow to to use xor to get one digit only when the above case

Thanks]]>