Skip to content

Commit

Permalink
byte compatible hex
Browse files Browse the repository at this point in the history
  • Loading branch information
futzu authored Jan 14, 2024
1 parent c7d5695 commit f7c8f26
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions threefive/bitn.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ def as_int(self, num_bits):
if self.idx >= num_bits:
self.idx -= num_bits
return (self.bits >> (self.idx)) & ~(~0 << num_bits)
# return self.negative_shift(num_bits)
return False

def as_hex(self, num_bits):
"""
Returns the hex value
of num_bits of bits
"""
return hex(self.as_int(num_bits))
hexed = hex(self.as_int(num_bits))
return (hexed.replace('0x','0x0',1),hexed)[len(hexed) %2 == 0]


def as_charset(self, num_bits, charset="ascii"):
"""
Expand Down

0 comments on commit f7c8f26

Please sign in to comment.