mirror of https://github.com/dirtbags/netarch.git
Added Alex's pp function
This commit is contained in:
parent
dc12a01a55
commit
a6f0d4f30a
|
@ -110,7 +110,7 @@ def assert_in(a, *b):
|
|||
|
||||
|
||||
##
|
||||
## Binary stuff
|
||||
## Binary and other base conversions
|
||||
##
|
||||
|
||||
class BitVector:
|
||||
|
@ -206,6 +206,12 @@ def unhex(s):
|
|||
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
|
||||
##
|
||||
|
|
Loading…
Reference in New Issue