Welcome to the Linux community forum and interact with 2 million technical staff to access the bitwise AND binary operations. The Code is as follows: [php]? Php $ a1; $ b2; $ c $ a ^ B; echo $ c3? Here we do not simply convert the addition relationship decimal 1 to binary 00000001 decimal 2 to binary 00000010 by bit ^ 000
Welcome to the Linux community forum, and interact with 2 million technical staff> enter the bitwise AND mainly operate on the binary number. The Code is as follows: [php]? Php $ a = 1; $ B = 2; $ c = $ a ^ B; echo $ c // 3? Here we do not simply convert the addition relationship decimal 1 to binary 00000001 decimal 2 to binary 00000010 by bit ^ 000
Welcome to the Linux community forum and interact with 2 million technicians>
Bitwise AND operations are mainly performed on binary numbers.
The Code is as follows:
[Php]
$ A = 1;
$ B = 2;
$ C = $ a ^ B;
Echo $ c // 3
?>
This is not a simple addition.
Convert decimal 1 to binary 00000001
Convert decimal 2 to binary 00000010
Bitwise ^ 00000011 // The values of different values are regarded as 1 ^
Then,
[Html]
$ A = 1;
$ B = 2;
Echo $ a & $ c; // 1
?>
Convert decimal 3 to binary 00000011
Convert decimal 1 to binary 00000001
Bitwise & 00000001 // The value remains the same for each single digit. Otherwise, the value is 0.
Finally, we will introduce the usage; it makes no sense to return values after bitwise. It is mainly used to determine whether $ a exists in $ c. // There are many permission usage options.
[Html]
$ My_privilege = 15; // 1 + 2 + 4 + 8 have all Permissions
$ Pri = '';
$ Privilege_arr = array (8 => 'add', 4 => 'delete', 2 => 'change', 1 => 'query ');
Foreach ($ privilege_arr as $ k => $ v ){
$ K & $ my_privilege & $ Pri. = ''I have '. $ v.' Power
';
}
Echo $ Pri;
?>