This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hardkrash
Recipients hardkrash
Date 2010-03-04.21:46:44
SpamBayes Score 0.010673322
Marked as misclassified No
Message-id <1267739206.12.0.0725020069518.issue8062@psf.upfronthosting.co.za>
In-reply-to
Content
It is a common practice to separate hex digits with a "thousands" separator every 4 hex digits.

0x1234_abcd

Although python does not accept the _ as a thousands separator in hex notation, neither is the thousands separator in base 10


Snippet that prints hex thousands with a _ separator

number = 0xef5678abcd1234

def hex_thousands(number):
    txt="{0:X}".format(number)
    txt_out = ""
    i = range(-4,-1 * (len(txt) + 4), -4)
    ii = i[:]
    ii.insert(0, None)
    for (j, k) in zip(i, ii):
        if txt_out:
            txt_out = "_" + txt_out
        txt_out = txt[j:k] + txt_out
    return txt_out

print hex_thousands(number)
History
Date User Action Args
2010-03-04 21:46:46hardkrashsetrecipients: + hardkrash
2010-03-04 21:46:46hardkrashsetmessageid: <1267739206.12.0.0725020069518.issue8062@psf.upfronthosting.co.za>
2010-03-04 21:46:44hardkrashlinkissue8062 messages
2010-03-04 21:46:44hardkrashcreate