assert isinstance(b, int) and 0 <= b < (1 << width)
eq = True # both have no leading zeros so far...
for i in range(width):
- if (a >> i) & 1:
- if (b >> i) & 1:
- eq = True # both have no leading zeros so far...
- else:
- eq = False # different number of leading zeros
+ a_bit = (a >> i) & 1
+ b_bit = (b >> i) & 1
+ # `both_ones` is set if both have no leading zeros so far
+ both_ones = a_bit & b_bit
+ # `different` is set if there are a different number of leading
+ # zeros so far
+ different = a_bit != b_bit
+ if both_ones:
+ eq = True
+ elif different:
+ eq = False
else:
- if (b >> i) & 1:
- eq = False # different number of leading zeros
- else:
- pass # propagate results from lower bits
+ pass # propagate from lower bits
return eq