Skip to content

Instantly share code, notes, and snippets.

@dance2die dance2die/halfAdder.js
Last active Apr 14, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.