PHP bitwise AND OR (^, &)

Source: Internet
Author: User
Today, friends in a group of friends asked the next bit and or question.

PHP has been working for 1 years, maybe not quite familiar with this piece. Introduce this part to the novice friend here

Pressing is located primarily on binary number operations.

 
  

This is not a purely additive relationship.

Decimal 1 converted to binary 00000001

Decimal 2 converted to binary 00000010

The bitwise ^ 00000011//Is different is counted as 1 ^_^

And then

 
  

Decimal 3 converted to binary 00000011

Decimal 1 converted to binary 00000001

Bitwise & 00000001//Is the same as each single digit, otherwise it will be counted as 0

Finally introduce the following usage; The bitwise & return value is meaningless. It is mainly used to determine if $ A is present in $c//permission usage is much more.

 
  ' Increase ', 4=> ' delete ',2=> ' to ',1=> '); foreach ($privilege _arr as $k = $v) {  $k & $my _privilege &&  $Pri. = ' I have '. $v. ' Power
';} Echo $Pri;? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.