added hex methods

This commit is contained in:
2021-04-13 06:41:39 +00:00
parent 66aa7ee915
commit c63d2dd4bb
3 changed files with 39 additions and 0 deletions

View File

@@ -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)