Does Python need a '>>>' operator?

Martin v. Loewis martin at v.loewis.de
Mon Apr 15 10:10:38 EDT 2002


"Ken Peek" <Ken.Peek at SpiritSongDesigns.comNOSPAM> writes:

> | That's what I'm trying to tell you all the time: the
> | '>>>' operator is meaningless if it is defined as
> | "fill in zeroes". How does it know where to start
> | inserting zeroes?
> 
> No, it isn't meaningless:
> 
> The 'long' class has an internal representation for the
> long number.  The number of bytes that are currently
> being used to contain the number are known (internally)
> to the object.  The zeroes get shifted into the high bit
> of the number, no matter how many bytes are used to
> contain the number.

long integers are represented internally not in two's complement, but
with a sign and an absolute value. So right-shifting *already* shifts
in zeroes. That does not change the fact that -0xFFL >> 1 is -0x7FL -
even if the internal representation only uses a single byte.

> An int type simply shifts a zero into bit 31, so that
> this works the same as it will on a long.

No, that won't be the same: an int is internally represented with the
two's complement. Shifting in zeroes into the internal representation
would have different effect on ints and longs.

> The '>>' operator should also work the same for a long
> as it does for an int.

I agree, and I believe it already does.

> The '<<' operator should also work the same for a long
> as it does for an int.

I agree; that will need to change.

> The 'hex()' method should work the same for a long as
> it does for and int.

I agree; that will need to change.

> Why is this so confusing to you?  

I'm not confused. Why do you think I am?

Regards,
Martin



More information about the Python-list mailing list