Skip to content

Commit

Permalink
Fixing stupid signed integer arithmetic error
Browse files Browse the repository at this point in the history
  • Loading branch information
ckirsch committed Jan 15, 2025
1 parent d3b4e0e commit 4457d5c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/bitme.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ def is_value(self, value):

def get_unsigned_value(self, value):
assert self.is_value(value)
return -value if value < 0 else value
return 2**self.size + value if value < 0 else value

def get_signed_value(self, value):
assert self.is_value(value)
return -value if value >= 2**(self.size - 1) else value
return value - 2**self.size if value >= 2**(self.size - 1) else value

class Bool(Bitvector):
boolean = None
Expand Down

0 comments on commit 4457d5c

Please sign in to comment.