top | item 33365638 (no title) tslater2006 | 3 years ago > 10000> & 1111> ______> 1Wouldn't this result in 0 and not 1? discuss order hn newest knome|3 years ago Missing a 'not'.You would use `bool( nn and not (nn&(nn-1)) )`Let's try for 15 start 0b1111 sans1 0b1110 anded 0b1110 not 0b0000 Now 8 start 0b1000 sans1 0b0111 anded 0b0000 not 0b0001 It's basically a claim that, in binary, only powers of two won't have any overlapping bits between the initial number and that number minus one.Doesn't work for 0 so you have to special case it. sumnole|3 years ago 0 is correct. AND(bit1,bit2) returns 1 if and only if both input bits are 1.AND'ing each bit of the two numbers yields only 0 bits: 10000 &01111 ______ 00000
knome|3 years ago Missing a 'not'.You would use `bool( nn and not (nn&(nn-1)) )`Let's try for 15 start 0b1111 sans1 0b1110 anded 0b1110 not 0b0000 Now 8 start 0b1000 sans1 0b0111 anded 0b0000 not 0b0001 It's basically a claim that, in binary, only powers of two won't have any overlapping bits between the initial number and that number minus one.Doesn't work for 0 so you have to special case it.
sumnole|3 years ago 0 is correct. AND(bit1,bit2) returns 1 if and only if both input bits are 1.AND'ing each bit of the two numbers yields only 0 bits: 10000 &01111 ______ 00000
knome|3 years ago
You would use `bool( nn and not (nn&(nn-1)) )`
Let's try for 15
Now 8 It's basically a claim that, in binary, only powers of two won't have any overlapping bits between the initial number and that number minus one.Doesn't work for 0 so you have to special case it.
sumnole|3 years ago
AND'ing each bit of the two numbers yields only 0 bits: