I’m working with a system that uses the following permission scheme:
1 – Permission A
2 – Permission B
4 – Permission C
8 – Permission D
16 – Permission E
The permissions for a user is stored as the sum of the permission values. For example, if a user has permissions B, C, and D, 14 is the number that is stored. (2+4+8)
Is there a fast way to find out if the user has permission D that doesn’t involve a full expansion of the permission string? (Taking a power of two until greater than the stored number, subtracting off that power, until the target number is reached)
http://php.net/manual/en/language.operators.bitwise.php
or
or