PHP Bitwise operators

Source: Internet
Author: User
Tags bitwise bitwise operators

The bitwise operator allows you to set the bits specified in the integer number. If both the left and right arguments are strings, the bitwise operator will manipulate the ASCII value of the character.

<?phpecho 12 ^ 9; The output is ' 5 ' echo ' 12 ' ^ ' 9 '; Output fallback characters (ASCII 8)                    //(' 1 ' (ASCII)) ^ (' 9 ' (ASCII)) = #8echo "Hallo" ^ "Hello",//output ASCII value #0 #4 #0 #0 #0 
     
      //' A ' ^ ' e ' = #4echo 2 ^ "3"; Output 1              //2 ^ ((int) "3") = = 1echo "2" ^ 3;//Output 1              //((int) "2") ^ 3 = = 1                            ?>
     
Bitwise operators
Example name Results
$a & $b and (Bitwise AND) A bit of 1 in both $a and $b will be set to 1.
$a | $b or (bitwise OR) The 1 bit in the $a or $b is set to 1.
$a ^ $b XOR (Bitwise XOR) The different bits in the $a and $b will be set to 1.
~ $a Not (bitwise non) Set the bit to 0 in the $a to 1, and vice versa.
$a << $b Shift left Moves the bits in the $a to the left $b times (each move represents "multiplied by 2").
$a >> $b Shift Right (move to left) Moves the bits in the $a to the right $b times (each move represents "divided by 2").
Warning

do not move more than 32 bits to the right on a 32-bit system . do not move left in cases where the result may be more than 32 bits .

http://bbs.dzwww.com/forum.php?mod=viewthread&tid=53319881

http://bbs.dzwww.com/forum.php?mod=viewthread&tid=53319915

http://bbs.dzwww.com/forum.php?mod=viewthread&tid=53319954

PHP Bitwise operators

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.