Bitwise Operators in PHP

Bitwise Operators in PHP

PHP Bitwise Operators are used to perform operations on individual bits of binary numbers. These operators work on integers and convert them into binary form to perform operations.

There are six Bitwise Operators in PHP:

  1. & (Bitwise AND): Returns a binary number where each bit is 1 only if the corresponding bits of both operands are 1.
  2. | (Bitwise OR): Returns a binary number where each bit is 1 if either of the corresponding bits of both operands is 1.
  3. ^ (Bitwise XOR): Returns a binary number where each bit is 1 if the corresponding bits of both operands are different.
  4. ~ (Bitwise NOT): Returns the complement of the binary number. Each 1 becomes 0 and each 0 becomes 1.
  5. << (Left Shift): Shifts the bits of the left operand to the left by the number of positions specified in the right operand.
  6. (Right Shift): Shifts the bits of the left operand to the right by the number of positions specified in the right operand.

These operators are commonly used in programming to manipulate binary data and flags.

Apply for PHP Certification!

https://www.vskills.in/certification/certified-php-developer

Back to Tutorials

Share this post
[social_warfare]
Formatting the date display
MS-EXCEL 2003

Get industry recognized certification – Contact us

keyboard_arrow_up