Octal notation: severe deprecation
Bengt Richter
bokr at oz.net
Fri Jan 14 02:10:57 EST 2005
On Thu, 13 Jan 2005 17:43:01 -0600, Jeff Epler <jepler at unpythonic.net> wrote:
>
>--LQksG6bCIzRHxTLp
>Content-Type: text/plain; charset=us-ascii
>Content-Disposition: inline
>Content-Transfer-Encoding: quoted-printable
>
>On Thu, Jan 13, 2005 at 11:04:21PM +0000, Bengt Richter wrote:
>> One way to do it consistently is to have a sign digit as the first
>> digit after the x, which is either 0 or base-1 -- e.g., +3 and -3 would be
>>=20
>> 2x011 2x101
>> 8x03 8x75
>> 16x03 16xfd
>> 10x03 10x97
>
>=2E.. so that 0x8 and 16x8 would be different? So that 2x1 and 2x01 would
>be different?
I guess I didn't make the encoding clear enough, sorry ;-/
16x8 would be illegal as a literal, since the first digit after x is not 0 or f (base-1)
0x8 would be spelled 16x08 in <base>x format.
2x1 _could_ be allowed as a degenerate form of the general negative format for -1, where
any number of leading base-1 "sign digits" compute to the same value. Hence
2x1 == 1*2**0 - 2**1 == -1
2x11 == 1*2**0 + 1*2**1 - 2**2 == 1 + 2 -4 == -1
2x111 == 1*2**0 + 1*2**1 + 1*2**2 - 2**4 == 1 + 2 + 4 - 8 == -1
16f == 15*16**0 - 16**1 = 15 -16 == -1
16ff == 15*6**0 + 15*16**1 - 16**2 = 15 + 240 - 256 == -1
etc. Although IMO it will be more consistent to require a leading "sign digit" even if redundant.
The one exception would be zero, since 00 doesn't look too cool in company with a collection
of other numbers if output minimally without their (known) base prefixes, e.g.,
-2,-1,0,1,2 => 110 11 0 01 010
Of course these numbers can be output in constant width with leading pads of 0 or base-1 digit according
to sign, e.g., 1110 1111 0000 0001 0010 for the same set width 4. That would be format '%04.2b' and
if you wanted the literal-making prefix, '2x%04.2b' would produce legal fixed width literals 2x1110 2x1111 etc.
Regards,
Bengt Richter
More information about the Python-list
mailing list