PHP median Operator

Source: Internet
Author: User

 

PHP median Operator
Bitwise operations are performed in units of bit, and 0 and 1 are performed in the computer. We usually perform operations in decimal format to conform to the reading habits of ordinary people, but the computation is still expressed as 0 and 1 in the computer.

Bitwise operators include the following:

Bitwise operators (sorted by operator priority)

Integration direction Logical operators Name Example

Non-Integration

~

Non-bitwise

~ $

Left

<
>

Move left
Right Shift

$ A <$ B
$ A> $ B

Left

&

Bitwise AND

$ A & $ B

Left

^

Bitwise OR

$ A ^ $ B

Left

|

By bit or

$ A | $ B

The left link in "link direction" indicates that the expression is evaluated from left to right, and the right link is opposite.
In the era of logical operations, 1 represents truth, and 0 represents false. The preceding table is as follows:

~(Not by bit): reverse

$ ~ $

0

1

1

0

&(Bitwise AND): both are 1Time is 1Otherwise, the value is 0.

$ $ B $ A & $ B

0

0

0

0

1

0

1

0

0

1

1

1

^(Bitwise OR): the two values are not the same as 1., The two are the same as 0

$ $ B $ A ^ $ B

0

0

0

0

1

1

1

0

1

1

1

0

|(By bit or): one of the two is 1.It is 1.Otherwise, the value is 0.

$ $ B $ A | $ B

0

0

0

0

1

1

1

0

1

1

1

1

Example:
<? PHP
$ A = 12; // 12 = 00001100
$ B = 3; // 3 = 00000011
Echo $ A & $ B. "<br/>"; // The displayed result is: 0.
Echo $ A ^ $ B. "<br/>"; // The displayed result is: 15
Echo $ A | $ B. "<br/>"; // The displayed result is: 15
Echo $ A <$ B. "<br/>"; // The result is 96.
Echo $ A >>$ B. "<br/>"; // The result is 1.
Echo ~ $ A; // The displayed result is-13.

?>

$ A & $ B: If both values are 1, the value is 1. Otherwise, the value is 0. Set the bits whose values are 1 in both $ A and $ B to 1; otherwise, set them to 0.
0000 1100 RMB $
& Amp; 0000 0011 RMB $ B
--------------------------------------
0000, 0000 = 0

$ A ^ $ B: the two values are not the same as 1, and the two values are the same as 0. Set the bitwise of $ A and $ B to 1 and the same bitwise to 0.
0000 1100 RMB $
^ 0000 0011 rows $ B
--------------------------------------
0000 1111 = 15

$ A | $ B: one of the two is 1, otherwise it is 0. Set the bit where $ A or $ B is 1 to 1; otherwise, set it to 0.
0000 1100 RMB $
| 0000 0011 bytes $ B
--------------------------------------
0000 1111 = 15

$ A <$ B: Move the bits in $ A to the left for $ B (each movement represents "multiplied by 2", that is, "multiplied by 2 $ B ").
0000 1100 RMB $
<0110 0000 move three to the left, and fill in 0 for the empty location
--------------------------------------
0110 0000 = 96

$ A >> B B: Move the bits in $ A to the right $ B (each movement means "divided by 2", that is, "multiplied by 2-$ B ").
0000 1100 RMB $
<0000 0001 shifted three to the right, and the extra positions are truncated.
--------------------------------------
0000 0001 = 1 this article from: http://hi.baidu.com/e9151/blog/item/5af3fb39c5f236c5d46225ec.html/cmtid/c58cba18d6233975dbb4bd4d

 

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.