Does Python need a '>>>' operator?

Ken Peek Ken.Peek at SpiritSongDesigns.comNOSPAM
Sat Apr 13 15:44:16 EDT 2002


Since Python does not have unsigned numbers, I think Python should have a
(Java-like) '>>>' operator.  The '>>>' means 'logical-shift-right', where a zero
is copied into the high bit.  This would be kind of nice when doing some logical
bit tweaking...

Here is some code to implement the '>>>' operator. (Unfortunately, this code
does not work for long integers):

# logical-shift-right operator:
def lsr(i,n):
    if n: i = i >> n ^ 0x80000000 >> n - 1
    return i

Although the '<<' and '>>' operators do not now "do the expected thing" with
long integers, they COULD if we introduced the '>>>' operator.  In order to
support the "all integers are the same" model, I think that they should.  Thus,
for long integers '<<' and '>>' could give different answers than '*2' and '/2'.
(I don't know how to implement this properly for long integers without breaking
some old code though.)

If this was discussed before, then it needs to be discussed again, as we are now
trying to provide seamless integration of the 'int' and 'long int' types...






More information about the Python-list mailing list