Return the two's complement bit string of x in `bits` bits.
(x: int, bits: int)
| 4 | """ Dictionary subclass that we will configure to show binary representations. """ |
| 5 | |
| 6 | def twos_complement(x: int, bits: int) -> str: |
| 7 | """Return the two's complement bit string of x in `bits` bits.""" |
| 8 | mask = (1 << bits) - 1 |
| 9 | return format(x & mask, f"0{bits}b") |
| 10 | |
| 11 | # configure memory_graph to show binary representations of values of type Bits |
| 12 | mg.config.type_to_node[Bits] = lambda x : mg.Node_Table(x, |