php Now

php Right Shift Operator

Site Logo

Form

<shift-operator>  ::=  <leftshift-operator>
   |  <rightshift-operator>
<leftshift-operator>  ::=  <<
<rightshift-operator>  ::=  >>

Semantics

 

>> (>>: integer × integer → integer)
name: Right Shift
operand types: integer
result type: integer
result value: The bits of the left operand are shifted right by the number of positions of the right operand.  The bit positions vacated on the left are filled with the sign bit, and bits shifted out on the right are discarded.
side effect: None.
associativity: Left to right.

Remarks

Example

<?php
  RightShift (4, 2);
  RightShift (-1, 5);
  RightShift (-1, -5);
  RightShift (2147483647, 32);
  RightShift (2147483647, 1);
  RightShift (0x80000001, 1);

function RightShift ($A, $B) {
  echo  "$A >> $B = ", ($A >> $B), "\n";
}
?>

Output

4 >> 2 = 1
-1 >> 5 = -1
-1 >> -5 = -1
2147483647 >> 32 = 2147483647
2147483647 >> 1 = 1073741823
2147483649 >> 1 = -1073741824

See Also

php Right Shift Expression  php Right Shift Expression  <rightshift-expression>
php Left Shift Operator  php Left Shift Operator  <leftshift-operator>
php Now Home  php Now Home
Etymology Index  Etymology Index
Operator Index  Operator Index
E-Mail
Valid HTML 4.01 Transitional Valid CSS! Site Logo

copyright 2005-2006, j.h.young, revised 2/9/06

php Right Shift Expression / php Left Shift Operator /