def _rshift_nearest(x, shift):
 (b, q) = ((1L << shift), (x >> shift))
 return (q + (((2 * (x & (b - 1))) + (q & 1)) > b))

def _rshift_nearest ( x , shift ) : ( b , q ) = ( ( 1 L << shift ) , ( x >> shift ) ) return ( q + ( ( ( 2 * ( x & ( b - 1 ) ) ) + ( q & 1 ) ) > b ) )
given an integer x and a nonnegative integer shift .