Hi There,
I DID do some searching but bitwise operations are still new to me and didn't find anything out.
Doubles are 1,2,4,8,16,32,64, etc. - these are the binary 0 and 1 places. That much I understand.
So, here is a function I'd like to write elegantly,
function bitwise_op($body, $place, $op='write'){
//function here, $op can also be 'read' - see below
}
some examples:
bitwise_op(7, 2); //returns 7 since 2 is already there
bitwise_op(5, 2); //returns 7 because 2 was added to 1+4
bitwise_op(7,-2); //returns 5 because the 2 was present and was subtracted
bitwise_op(5,-2); //returns 5 because the 2 was NOT present and couldn't be subtracted
bitwise_op(15,4, 'read'); //returns true because 4 is in 1+2+4+8
bitwise_op(30,1, 'read'); //returns false because 1 is not in 2+4+8+16
This is probably very easy - and I'd be glad to work with hints, thanks.
Samuel