[Tutor] HD/DVD/CD

Terry Carroll carroll at tjc.com
Wed Jan 4 03:13:43 CET 2006


On Wed, 4 Jan 2006, John Fouhy wrote:

> On 04/01/06, Terry Carroll <carroll at tjc.com> wrote:
> > I hope someone more artful than I can show a quick and easy way to convert
> > either '758C87F3' or -1972144115 to the '8A73780D'  that is your goal.
> 
> Hmm, well,
> 
> >>> i = -1972144115
> >>> '%X' % (pow(2, 32)-(~i+1))
> '8A73780D'

Aha, I also figured another way myself in the meantime:

>>> import win32api
>>> CD_Info = win32api.GetVolumeInformation("D:/")
>>> serno = CD_Info[1]
>>> serno_str = "%X" % (0x100000000+serno)
>>> serno_str
'8A73780D'
>>>

> >>> cdi = win32api.GetVolumeInformation('D:/')
> >>> '%X' % cdi[1]
> '49BC31DB'
> 
> So, on my system (ActivePython 2.4, WinXPpro) there is no need for magic.

I think you just got lucky that your first digit (4) was in the range 0-7, 
and so didn't generate a negative.

But you *do* point out a fault in my approach.  I'll give an incorrect
result for a non-negative.  I think the correct way is:

>>> import win32api
>>> CD_Info = win32api.GetVolumeInformation("D:/")
>>> serno = CD_Info[1]
>>> if serno < 0:
...    serno_str = "%X" % (0x100000000+serno)
... else:
...    serno_str = "%X" % serno
...
>>> serno_str
'8A73780D'
>>>




More information about the Tutor mailing list