static function shift_right($g, $shift)
  {
    if (0 == $shift)
      return $g;

    if (0 <= gmp_sign($g))
      $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift));
    else // negative
    {
      $g = gmp_and($g, self::gmp_0xfs());
      $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift));
      $m = gmp_and($m, self::gmp_0xfs());
      for ($i = 63; $i >= (63 - $shift); $i--)
        gmp_setbit($m, $i);

      $m = gmp_neg(gmp_add(gmp_and(gmp_com($m), self::gmp_0xfs()),
                           self::gmp_1()));
    }

    return $m;
  }
static function shift_right($g, $shift)
  {
    if (0 == $shift)
      return $g;

    if (0 <= gmp_sign($g))
      $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift));
    else // negative
    {
      $g = gmp_and($g, self::gmp_0xfs());
      $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift));
      $m = gmp_and($m, self::gmp_0xfs());
      for ($i = 63; $i >= (63 - $shift); $i--)
        gmp_setbit($m, $i);

      $m = gmp_neg(gmp_add(gmp_and(gmp_com($m), self::gmp_0xfs()),
                           self::gmp_1()));
    }

    return $m;
  }
static function shift_right ( $ g , $ shift ) { if ( 0 == $ shift ) return $ g ; if ( 0 <= gmp_sign ( $ g ) ) $ m = gmp_div ( $ g , gmp_pow ( self :: gmp_2 ( ) , $ shift ) ) ; else // negative { $ g = gmp_and ( $ g , self :: gmp_0xfs ( ) ) ; $ m = gmp_div ( $ g , gmp_pow ( self :: gmp_2 ( ) , $ shift ) ) ; $ m = gmp_and ( $ m , self :: gmp_0xfs ( ) ) ; for ( $ i = 63 ; $ i >= ( 63 - $ shift ) ; $ i -- ) gmp_setbit ( $ m , $ i ) ; $ m = gmp_neg ( gmp_add ( gmp_and ( gmp_com ( $ m ) , self :: gmp_0xfs ( ) ) , self :: gmp_1 ( ) ) ) ; } return $ m ; }
Arithmetic right shift
@param resource|int|string $g
@param int $shift number of bits to shift right
@return resource $g shifted right $shift bits
Arithmetic right shift