Next: Binary bit-wise operations Up: Expressions and conditions Previous: Binary arithmetic operations

Shifting operations

The shifting operations have lower priority than the arithmetic operations:


shift_expr:     a_expr | shift_expr ( "<<" | ">>" ) a_expr

These operators accept plain or long integers as arguments. The arguments are converted to a common type. They shift the first argument to the left or right by the number of bits given by the second argument.

A right shift by [tex2html_wrap1136]bits is defined as division by [tex2html_wrap1138]. A left shift by [tex2html_wrap1140]bits is defined as multiplication with [tex2html_wrap1142]; for plain integers there is no overflow check so this drops bits and flip the sign if the result is not less than [tex2html_wrap1144]in absolute value.

Negative shift counts raise a ValueError exception.


guido@cwi.nl