Apologies - I'm not even sure I'm using the right terminology here.
I have a series of confidential documents and I'm creating a bitmask (?) to represent which of those documents a given user can view. (1 represents Doc1, 2 represents Doc2, 4 represents Doc3, 8 represents Doc4, 16 represents Doc5, etc.)
So, if a user can view docs 1, 2, and 5, the bitmask will be 19.
Where I'm really stumped, though, is how to reverse calculate the individual values "stored" in the bitmask. Currently, I'm using
if($docs2view==1) {
$nextdoc = 1;
}
if($docs2view==2) {
$nextdoc = 2;
}
. . .
if($docs2view==127) {
$nextdoc = 1;
}
which is REALLY tedious and obviously very inefficient. Can someone point me toward the right way to do this?