why is a negative shift value illegal?

Chris Ryland cpr at emsoftware.com
Sat Jan 13 18:56:52 EST 2001


>From 2.0 manual, 5.7:

'''A right shift by n bits is defined as division by pow(2,n). A left shift
by n bits is defined as multiplication with pow(2,n); for plain integers
there is no overflow check so in that case the operation drops bits and
flips the sign if the result is not less than pow(2,31) in absolute value.
Negative shift counts raise a ValueError exception.'''

Why shouldn't negative shifts just mean a shift in the opposite direction?
To avoid confusion? Becuse there's only way way to do things in Python?

E.g., 16 << -2 seems like it might well be defined as 16 >> 2.

Cheers!
Chris Ryland, President * Em Software, Inc. * www.emsoftware.com





More information about the Python-list mailing list