diff --git a/language/operators.xml b/language/operators.xml index 5b8839b041..b51bebc07c 100644 --- a/language/operators.xml +++ b/language/operators.xml @@ -1,5 +1,5 @@ - + Operators @@ -441,7 +441,6 @@ $b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!"; Right shifts have copies of the sign bit shifted in on the left, meaning the sign of an operand is preserved. - Use parentheses to ensure the desired precedence. @@ -450,13 +449,66 @@ $b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!"; ($a & $b) == true evaluates the bitwise and then the equivalency. - Be aware of data type conversions. If both the left-hand and right-hand parameters are strings, the bitwise operator will operate on the characters' ASCII values. - + + + + +PHP's error_reporting ini setting uses bitwise values, +providing a real-world demonstration of turning +bits off. To show all errors, except for notices, +the php.ini file instructions say to use: +E_ALL & ~E_NOTICE + + + + +This works by starting with E_ALL: +00000000000000000111011111111111 +Then taking the value of E_NOTICE... +00000000000000000000000000001000 +... and inverting it via ~: +11111111111111111111111111110111 +Finally, it uses AND (&) to find the bits turned +on in both values: +00000000000000000111011111110111 + + + + +Another way to accomplish that is using XOR (^) +to find bits that are on in only one value or the other: +E_ALL ^ E_NOTICE + + + + + + + + +error_reporting can also be used to demonstrate turning bits on. +The way to show just errors and recoverable errors is: +E_ERROR | E_RECOVERABLE_ERROR + + + + +This process combines E_ERROR +00000000000000000000000000000001 +and +00000000000000000001000000000000 +using the OR (|) operator +to get the bits turned on in either value: +00000000000000000001000000000001 + + + + Bitwise AND, OR and XOR operations on integers