Does Python need a '>>>' operator?

Martin v. Loewis martin at v.loewis.de
Mon Apr 15 17:06:43 EDT 2002


bokr at oz.net (Bengt Richter) writes:

> IMO 'internal representation' is a red herring. We have an abstract
> concept of number representation (twos complement) that corresponds
> to many hardware devices' usage, but it is the abstraction that is
> important IMO, not the hardware.

Yes, but this notion is inherently bound with the notion of "size" of
an integer, atleast in the signed variant (for unsigned integers,
there is no need for twos complement). If you create the complement,
you have to know how many bits to invert.

I absolutely agree with your (earlier) conclusion that bit arithmetic
is best done with unsigned numbers.

> When looking at integers cast as arrays of booleans, hex provides a
> representation, but w.r.t. boolean values it is not very useful to
> print it as base-16 integer with sign+absolute value.

I also agree.

> If I infer correctly, Ken is arguing that hex is more often used to
> view the boolean aspect of integers than their numeric
> aspect. That's true for me too.

And so it is for me. Still, I disagree that a display of a hex number
with a sign is illogical or incorrect. In fact, when talking about
"unbounded" numbers, it is illogical to assume twos complement.

> >Yes-- I read the PEP too-- when this happens, I will consider it a
> >Python "_WART_", and will set about inventing ways around it for my
> >own use.  I have forgotten more computer languages than most people
> >will ever learn-- an I have NEVER found printing a hexadecimal
> >number in sign and magnitude format to be useful...
>
> I'll second that.

At a minimum, you need to propose an alternative behaviour then. I
must say that I don't find the proposed behaviour of mandatory leading
zeroes (the 0h proposal) very intuitive, or following tradition.

Instead, there is a simple solution: use unsigned numbers if you want
to represent bit arrays.

> I would guess so. I do. But for language purposes my preference is
> to refer to an abstract bit pattern, not hardware (even though
> hardware mappings will exist and be useful).

That is only meaningful for positive numbers - it just doesn't work
for twos complement.

Regards,
Martin



More information about the Python-list mailing list