PHP bit Operation vs. XOR or negation

Source: Internet
Author: User

<?PHP/*There are 4 bit operations in the *php, respectively, & and | or ^ XOR ~ Take counter & two bits are all 1, the result is that 1| has one for 1, the result is 1^ one is 0, one is 1, the result is 1~ take anti-0->1,1->01. The highest bit of the binary is the sign bit, 0 indicates a positive number and 1 indicates a negative number. 2. Positive number of the original code, anti-code, the same complement. 3. Negative number of the inverse code = Its original code sign bit is unchanged, the other bits take the reverse (0->1,1->0). 4. The complement of negative number = its inverse code +1. 5.0 of the anti-code, the complement is 0.6.php no unsigned number, in other words, the number in PHP is signed. 7. At the time of computer operation, it is all in the form of a complement. **/ //XOR orEcho -&7; Echo"<br/>"; Echo5|4; Echo"<br/>"; Echo-3^3;//Inference Process:/**13&713 's Complement 00000000 00000000 00000000 000011017 Complement 00000000 00000000 00000000 0000011113&7 00000000 00      000000 00000000 00000101 = 55|45 's Complement 00000000 00000000 00000000 000001014 Complement 00000000 00000000 00000000 000001005|4 00000000 00000000 00000000 000000101 =5-3^3-3 's complement-3 of the original code 10000000 00000000 00000000 00000011-3 Anti-code 11111111 11111111 1111111 1 11111100-3 of the complement 11111111 11111111 11111111 11111101
PHP bit operations and/or XOR and iterative code<?PHP/*There are 4 bit operations in the *php, respectively, & and | or ^ XOR ~ Take counter & two bits are all 1, the result is that 1| has one for 1, the result is 1^ one is 0, one is 1, the result is 1~ take anti-0->1,1->01. The highest bit of the binary is the sign bit, 0 indicates a positive number and 1 indicates a negative number. 2. Positive number of the original code, anti-code, the same complement. 3. Negative number of the inverse code = Its original code sign bit is unchanged, the other bits take the reverse (0->1,1->0). 4. The complement of negative number = its inverse code +1. 5.0 of the anti-code, the complement is 0.6.php no unsigned number, in other words, the number in PHP is signed. 7. At the time of computer operation, it is all in the form of a complement. **/ //XOR orEcho -&7; Echo"<br/>"; Echo5|4; Echo"<br/>"; Echo-3^3;//Inference Process:/**13&713 's Complement 00000000 00000000 00000000 000011017 Complement 00000000 00000000 00000000 0000011113&7 00000000 00      000000 00000000 00000101 = 55|45 's Complement 00000000 00000000 00000000 000001014 Complement 00000000 00000000 00000000 000001005|4 00000000 00000000 00000000 000000101 =5-3^3-3 's complement-3 of the original code 10000000 00000000 00000000 00000011-3 Anti-code 11111111 11111111 1111111 1 11111100-3 complement 11111111 11111111 11111111 111111013 Complement 00000000 00000000 00000000 00000011-3^3 11111111 11111111 1111 1111 11111110 "complement" push anti-code "to complement-1" 11111111 11111111 11111111 11111101 "anti-code" push the original code "symbol bit invariant other inversion" 10000000 00000000 00000000 0000 0010 "Original Code" =-2 Note: Because the binary does not carry and abdication, can be regarded as 10-1, that is equal to 1 **/?>

3 Complement 00000000 00000000 00000000 00000011-3^3     11111111 11111111 11111111 11111110  "complement" push back code "to complement-1"  11111111 11111111 11111111 11111101   "anti-code" push the original code "symbol bit invariant other inversion"  10000000 00000000 00000000 00000010   "original code"  =- 2 Note: Because the binary does not carry and abdication, can be regarded as 10-1, that is equal to 1 * * */?>

PHP bit Operation vs. XOR or negation

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.