Skip to content

Instantly share code, notes, and snippets.

@dougallj
dougallj / gist:9211fd24c3759f7f340dede28929c659
Last active June 5, 2024 04:21 — forked from zwegner/gist:6841688fa897aef64a11016967c36f2d
Ternary logic multiplication (0, 1, unknown)
N_BITS = 8
MASK = (1 << N_BITS) - 1
class Ternary:
def __init__(self, ones, unknowns):
self.ones = ones & MASK
self.unknowns = unknowns & MASK
assert (self.ones & self.unknowns) == 0, (bin(self.ones), bin(self.unknowns))
def __add__(self, other):