Does Python need a '>>>' operator?

logistix logstx at bellatlantic.net
Sat Apr 13 20:07:28 EDT 2002


There's a bit of a semantic distinction here.  In reality, bitwise
operations hit primitives like BYTES and WORDS (or DWORDS), not ints.  The
fact that ints are equivilent to words is just a conincidence that we take
advantage of.  The whole concept of "performing bitwise operations on
integers" is totally illogical (even though I do it too ;) ) but it's alot
easier to use ints as words instead of creating a distinct type.

Now a long integer is an arbitrary complex structure (in the sense that
processors don't support long integers at the machine code level), so it's
really impractical to perform some sort of official, definitive bitwise
operation on.

So what does Python do? Mimic the behavior to achieve expected results, even
though it's not performing a genuine bit shift.  Makes sense to me.

--
-

"Ken Peek" <Ken.Peek at SpiritSongDesigns.comNOSPAM> wrote in message
news:3cb88ae7 at news.mhogaming.com...
> 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