PHP wrote a few years people are curious to say, have not used the site operator. So, here you see the look of binary dizziness, went to T ¥ M ¥ D bar.
Bitwise operators the basic need, we will have the knowledge to understand the level. Knowledge point operator, you do not want to learn can. And other operations in place after a time, come to learn it. FIG processing member to the marble
Learning to understand the knowledge level [level] can be impressed.
For example | Explanation | Detailed description |
---|---|---|
$a & $b | And (bitwise AND) | Will be $ a and $ b in both the 1 bits set to 1. |
$a | $b | Or (bitwise OR) | Will be $ a and $ b in any one of 1 bit is set to 1. |
$a ^ $b | XOR (bitwise exclusive or) | $ B in $ a is 1 and the other is a bit 0 set to 1. |
~ $a | Not (bitwise) | $ A for the 0 bit set to 1, and vice versa. |
$a << $b | The left | The $ a $ b in the sub-bit shift to the left (each step means "multiply by 2"). |
$a >> $b | Right | The $ a in $ b times a bit to the right (each step means "divide by 2"). |
Above symbols are binary operations.
Binary most cases you will not encounter, met up about binary this one will be the knowledge.
<? PHP // binary value X $: $ X =. 5; // binary value Y $: $ Y =. 8; // result 13 is echo $ X $ Y ^; ?>
variable | Binary values |
---|---|
$x | 0101 |
$ and | 1000 |
XOR result | 1101 |
XOR explanation: If the x, y two values are not the same, the result is an exclusive OR. If the x, y values are the same, the exclusive OR result is 0.
Whereby pushing 1101 to $ x and $ y out of the result of the exclusive OR, the result of 1101 rpm for converting binary decimal tool 13 on.