Added Alex's pp function

This commit is contained in:
Neale Pickett 2008-07-15 16:29:34 -06:00
parent dc12a01a55
commit a6f0d4f30a
1 changed files with 7 additions and 1 deletions

View File

@ -110,7 +110,7 @@ def assert_in(a, *b):
## ##
## Binary stuff ## Binary and other base conversions
## ##
class BitVector: class BitVector:
@ -206,6 +206,12 @@ def unhex(s):
return [ord(i) for i in s.replace(' ', '').decode('hex')] return [ord(i) for i in s.replace(' ', '').decode('hex')]
def pp(value, bits=16):
if type(value) == type(''):
value, _ = unpack('<H', value)
hexfmt = '%%0%dx' % (bits / 4)
return '%6d 0x%s %s' % (value, (hexfmt % value), bin(value, bits))
## ##
## Codecs ## Codecs
## ##