Home >Backend Development >PHP Tutorial >PHP base and bit operations_PHP tutorial

PHP base and bit operations_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:07:211116browse

php base and bit operations

//八进制 ,前面加0代表8进制
echo 0123 , &#39;<br/>&#39;; //十进制83 从右到左3个位,分别是以1顶1,以1顶8 ,以1顶64
echo 027 , &#39;<br/>&#39;;//23
 
//十六进制,前面加0x代表16进制 , 0 1 2 3 4 5 6 7 8 9 a b c d e f 
echo 0x123 , &#39;<br/>&#39;;//十六进制 从右到左3个位,分别是以1顶1,以1顶16 ,以1顶256
echo 0x27 ."<br>";
echo 0x1c ."<br>"; //28
 
//二进制 ,php目前不支持直接表示 ,从右到左,分别以1顶1,顶2,顶4,顶8.....
/*
10进制       2进制
5        0000 0101
255          1111 1111        
*/
 
//位运行符,&位与运算符 , | 位或运算符
echo 5&12 ,&#39;<br/>&#39;; //6
echo 5|12 ,&#39;<br/>&#39;; //13
 
echo 5^12 ,&#39;<br/>&#39;;//异或 9
 
echo ~5 ,&#39;<br/>&#39;;//取反
 
//利用位运算的左移一位,使整数增大2倍;相应得位运算的右移一位,使整数减小2倍
$a=3;
echo $a << 1 ,&#39;<br/>&#39;;//6
echo $a << 2 ,&#39;<br/>&#39;;//12
 
 
// 赋予权限值-->(删除:8)( 上传:4) (写入:2) (只读:1)
define(&ldquo;mDELETE&rdquo;,8);
define(&ldquo;mUPLOAD&rdquo;,4);
define(&ldquo;mWRITE&rdquo;,2);
define(&ldquo;mREAD&rdquo;,1);
 
//部门经理的权限为(假设它拥有此部门的所有权限)
echo mDELETE|mUPLOAD|mWRITE|mREAD // 相当于是把上面的权限值加起来:8+4+2+1=15
 
// 设我只有 upload 和 read 权限,则
echo mUPLOAD|mREAD

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1061304.htmlTechArticlephp Base and bit operations//Octal, add 0 in front to represent octal echo 0123, br/; / /Decimal 83 has 3 digits from right to left, 1 is used as 1, 1 is used as 8, and 1 is used as 64echo 027, br/;//23 //Hexadecimal...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn