Annoying octal notation

Harald Luessen harald.luessen at gmx.de
Mon Aug 24 13:18:16 EDT 2009


On Mon, 24 Aug 2009 Derek Martin wrote:
>Those participating in this thread have pretty much all seem to agree
>that the only places where decimal numbers with leading zeros really
>are common are either in rather specialized applications, such as
>computer-oriented data or serial numbers (which typically behave more
>like strings, from a computer science perspective), or the rather
>common one of dates.  The latter case is perhaps what's significant,
>if any of those cases are.

I don't like the 'leading 0 is octal'-syntax. I typically think of
numbers as decimal and bytes as hexadecimal.
I would even write something like this:

# iterate over bits 3 to 5
for i in range(0x00, 0x40, 0x08):
    ...
    print "0x%02x\n" % i

0x00
0x08
0x10
0x18
0x20
0x28
0x30
0x38

For me it is easier to see where the bits are in the hex notation.

And it is very common to use numbers with leading zeroes
that are hexadecimal. Like this:

# print address and data
for i in range(0x10000):
    print "%04x: %d\n" % i, data[i]

0000: ...
0001: ...
...
000f: ...
0010: ...
...

When you are looking for examples of numbers where leading zeroes
do not mean octal then consider decimal AND hexadecimal.

>I tend to think that within the computer
>science arena, the history and prevalence of the leading 0 indicating
>octal far outweighs all of those cases combined.

I disagree.

Harald




More information about the Python-list mailing list