[Wolves] Bitwise AND
Matthew Revell
wolveslug at understated.co.uk
Tue Jan 6 11:12:50 GMT 2004
Howdy Aq and Leep,
Aquarius said:
> Imagine two numbers in binary form:
>
> 00011010 -- 26 ( 0*128 + 0*64 + 0*32 + 1*16 + 1*8 + 0*4 + 1*2 + 1*1 )
> 10110110 -- 182 ( 1*128 + 0*64 + 1*32 + 1*16 + 0*8 + 1*4 + 1*2 + 0*1 )
So, if you did:
if ($n & 1 = 1) return "odd";
then the reason it can let you know if a number is odd or even is because
it can only ever match all the numbers with 1 if the number is odd.
So, that's cool, but what else would you want to use it for?
Cheers both for your answer.
Matthew.
More information about the Wolves
mailing list