I have a bitmask permissions + roles set:
{
EDIT: '1',
DELETE: '2',
ADD: '4',
VIEW: '8',
}
I'm looking for the simplest way to Extend and Revoke user permissions using bitwise operations.
For example a user has 7 set as permissions allowing him to EDIT, DELETE and ADD
I want to add VIEW and ADD or 12.
What is the simplest formula to extend 7 with 12 to become 15 and vice versa?
How could I revoke a users existing permissions 12 (VIEW, ADD) to revoke (DELETE, ADD) - 6 so that it would equal 8?
Ok I've figured out to extend you would use the
Bitwise OR (|)operator likeand to revoke, you would use the
Bitwise AND (&)and subtract it from the users permissions like: