On Wed, 4 Jan 2006, Kent Johnson wrote: > To get the desired representation, you have to find a way to make Python > interpret the number as an unsigned integer. One way to do this is to > convert it to a long integer, then mask off the sign bits: > >>> i = long(-1972144115) & 0xFFFFFFFF
Ah, thanks. I've never had a need to to bit manipulation in Python (or in anything since IBM S/390 assembler, for that matter), so this is terra incognito to me. That feels much cleaner to me than using an arithmetic addition; and is has the advantages of being shorter and addressing both positive and negative numbers with the same operation, rather than using the if. So, changing my previous code, I now like the short and sweet: >>> import win32api >>> CD_Info = win32api.GetVolumeInformation("D:/") >>> serno = "%X" % (long(CD_Info[1]) & 0xFFFFFFFF) >>> serno '8A73780D' _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor