Assume that a decimal number 10 is used to obtain the & 20540; (10> 0) & amp; 0x01 percentile & 20540; (10> 1) & amp; 0x01 penultimate & 20540; assume that there are binary numbers 101 to 10 hexadecimal $ res = 0; $ res | = (1 "/> <scripttype =" t
Assume there is a decimal number 10.
Obtain the value of each binary value of 10:
(10> 0) & 0x01 // delimiter value
(10> 1) & 0x01 // The second-to-last value
Assume there are 101 binary numbers
Convert to 10 hexadecimal
$ Res = 0;
$ Res | = (1 <0); // the low position is 1.
$ Res | = (1 <1); // The value of high is 1.
// The intermediate bit is not 1
Power as $ k =>v v) {if (in_array ($ v, $ user) {$ res |=( 1 <$ k );}} return $ res;} // obtain the permission list based on the int value function getPowerByInt ($ num) {$ res = array (); foreach ($ this-> power as $ k => $ v) {$ res [$ v] = ($ num >>$ k) & 0x01 ;} return $ res ;}}// assume that a user has the permission of P1 and P4 $ user = array ('p1', 'p4 '); $ test = new Test (); // view the int value of the user permission var_dump ($ test-> getPowerInt ($ user )); // output 9 // note that the order is in descending order. if a user has 0101 permissions, that is, only P1 and P3 are allowed, that is, decimal 5. // output the permission list var_dump ($ test-> getPower ByInt (5); // output array (4) {// ["P1"] => // int (1) // ["P2"] => // int (0) // ["P3"] => // int (1) // ["P4"] => // int (0) //} // ------------------ if the permission is insufficient, add the permission -------- // in reverse order. Add $ power/$ power = array (// "P1", // "P2", // "P3", // "P4 ", // "P5", //); // New test result: Old permissions are not affected. Old users do not have new permissions by default. // therefore, the role bit can be considered as the highest permission at the beginning of the design, all. // Var_dump ($ test-> getPowerInt ($ user); // output 9 // var_dump ($ test-> getPowerByInt (5); // output array (4) {// ["P1"] => // int (1) // ["P2"] => // int (0) // ["P3"] => // int (1) // ["P4"] => // int (0) // ["P5"] => // int (0 )//}