"&" bits and operators:
The bitwise AND operator "&" is the binocular operator. Its function is to participate in the operation of the two number of the corresponding binary phase. Only the corresponding two binaries are 1 o'clock, the result bit is 1, otherwise 0. The number of participating operations appears in a complementary fashion.
Such as:
00001001
&
00000101
=
00000001
The "|" bit or operator:
Bitwise OR operator ' | ' is the binocular operator. Its function is to participate in the operation of the two number of the corresponding binary phase or. As long as the corresponding two binary has one for 1 o'clock, the result bit is 1. The two numbers participating in the operation are in complement.
00001001
|
00000101
=
00001101
When you get user permissions, use the "|" operator to get user permission values, and use the "&" operator when comparing user permissions to compare whether a user has permission to do so. For example: User A has permissions:
Permission ID |
Permission value |
Permission Name |
1 |
1 |
Inquire |
2 |
2 |
New |
3 |
4 |
Delete |
4 |
8 |
Update |
Permission value =2^ (permission ID-1) User A's permission value =1|2|4|8=15 0001 |0010 |0100 |1000=1111 Determine if the user has delete permission 15&4!=0 operation result 1111&0100=0100 0100 = 4 is not equal to 0, indicating permission. If the user rights value = User A's permission value =1|2|8=11 0001 |0010 |1000=1011 Determine whether the user has delete permissions 11&4!=0 operation results 1011&0100=0000 0000=0 equals 0, indicating no permissions. Query permissions directly determine user A's permission value ==0 this way, as long as the user has any permissions can query the document.
"&" Bitwise AND operator "|" permission control algorithm for BITS or operators