Does Python need a '>>>' operator?

Ken Peek Ken.Peek at SpiritSongDesigns.comNOSPAM
Mon Apr 15 23:23:08 EDT 2002


"Jon Ribbens" <jon+usenet at unequivocal.co.uk> wrote in message
news:slrnablsp5.f08.jon+usenet at snowy.squish.net...
| In article <3cba62f8 at news.mhogaming.com>, Ken Peek wrote:
| > This should be fixed so that decimal display of longs uses the '-'
| > sign, but hex display does not (you would just get the number of hex
| > digits in their raw "twos complement" form that the long object's
| > hex display method "knows" there is...)
|
| So you think that:
|
|   long(hex(-1l), 16)
|
| should not equal -1 but, err, some random choice of 15, 255, 4095,
| 65535, etc?

No, since we are "unifying" the int and long type, it is none
of your business HOW they are stored-- so we do away with the
'int()' and 'long()' functions...

BTW-- since -1 can be represented by one byte, my proposal is
for 'hex()' to print this as '0xff'...

I happen to like doing this extension stuff a byte at a time--
others have suggested that a nibble representation may be
better, and in that case, hex(-1) would print as '0xf'...

If we are using the "nibble at a time" method, the positive
number 15 (as in: hex(15)), would print as: '0x0f', because
we need another hex digit to convey the sign.  This could be
shifted left 3 more times without having to add another hex
digit to preserve the sign bit...

Now, if we have a 32 bit machine, and I want to bit-twiddle a
160-bit number (lets say for my new and improved random number
generator or something), and I need to right shift it LOGICALLY
(shifting a zero into bit 159), we would need a '>>>' operator
to do that (because the '>>' operator will shift right
ARITHMETICALLY, causing the sign bit to be copied into bit
159).  Remember, the machine may be STORING the number in some
bazaar format that has nothing to do with a binary twos
complement number, but that is of no matter to us-- as we are
always presented with a binary twos complement number as the
'interface' to the number.  The class that owns the object
would have a '>>>' method, and when we use the '>>>' operator,
that method would be called.  HOW it actually performs this
work for us is really none of our business.

See?






More information about the Python-list mailing list