search
Homephp教程php手册PHP中的按位与和按位或操作

PHP中的按位与和按位或操作

Jun 06, 2016 pm 07:55 PM
linuxphpoperateCommunityforumEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 按位与主要是对二进制数操作。 代码如下: [php] ?php $a = 1; $b = 2; $c = $a^b; echo $c // 3 ? 这里不是单纯的相加关系 十进制 1换算成二进制 00000001 十进制 2换算成二进制 00000010 按位^ 000

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  按位与主要是对二进制数操作。

  代码如下:

  [php]

  

  $a = 1;

  $b = 2;

  $c = $a^b;

  echo $c  // 3

  ?>

  这里不是单纯的相加关系

  十进制 1换算成二进制  00000001

  十进制 2换算成二进制  00000010

  按位^                       00000011   // 就是不相同的都算成1 啦 ^_^

  然后,

  [html]

  

  $a = 1;

  $b = 2;

  echo $a & $c;  // 1

  ?>

  十进制 3换算成二进制 00000011

  十进制 1换算成二进制 00000001

  按位& 00000001 // 就是各个位数相同的不变否则都算成0

  最后介绍下用法 ; 按位&后返回值是没意义的。 主要是用来判断$a 是否存在于 $c // 权限用法比较多。

  [html]

  

  $my_privilege = 15;  // 1+2+4+8 拥有全部权限

  $Pri = '';

  $privilege_arr = array(8=>'增', 4=>'删',2=>'改',1=>'查');

  foreach($privilege_arr as $k =>$v){

  $k & $my_privilege &&  $Pri .= '我有'.$v.'的权力
';

  }

  echo $Pri;

  ?>

PHP中的按位与和按位或操作

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.