Skip to content

Instantly share code, notes, and snippets.

@dance2die
Last active April 14, 2019 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/6a002c4d417703cc31c0c02f8bbfe067 to your computer and use it in GitHub Desktop.
Save dance2die/6a002c4d417703cc31c0c02f8bbfe067 to your computer and use it in GitHub Desktop.
const xor = (a, b) => Boolean(a) !== Boolean(b);
const and = (a, b) => Boolean(a) && Boolean(b);
const toBit = predicate => (a, b) => (predicate(a, b) ? 1 : 0);
const xorBit = toBit(xor);
const andBit = toBit(and);
const halfAdder = (a, b) => ({ c: andBit(a, b), s: xorBit(a, b) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment