added hex methods
This commit is contained in:
15
src/bits.py
15
src/bits.py
@@ -921,6 +921,12 @@ class Bits:
|
||||
ret.append(Bit(b))
|
||||
return ret
|
||||
|
||||
def hex(self):
|
||||
"""
|
||||
Return the hex-string representation of self
|
||||
"""
|
||||
return bytes(self).hex()
|
||||
|
||||
|
||||
class Bytes:
|
||||
"""
|
||||
@@ -1125,6 +1131,15 @@ class Bytes:
|
||||
chop += 1
|
||||
return ret + bin(i)[chop:]
|
||||
|
||||
def hex(self, sep=None, bytes_per_sep=1):
|
||||
"""
|
||||
Return the hex-string representation of self
|
||||
"""
|
||||
if sep is None or bytes_per_sep is None or bytes_per_sep == 0:
|
||||
return bytes(self).hex()
|
||||
else:
|
||||
return bytes(self).hex(sep=sep, bytes_per_sep=bytes_per_sep)
|
||||
|
||||
@property
|
||||
def bytes(self):
|
||||
return bytes(self)
|
||||
|
Reference in New Issue
Block a user