Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const toDec = binaryText => parseInt(binaryText, 2);
[
["0", "0"], ["0", "1"], ["1", "0"], ["1", "1"],
["00", "10"], ["01", "00"], ["10", "00"], ["10", "01"],
["10", "10"], ["11", "00"], ["11", "01"],
["11", "10"], ["11", "11"], ["101", "001"],
["1111", "0011"], ["011111", "111111"],
["11011", "00001"], ["11111111", "00000001"]
].map(([a, b]) =>
log(`${a} + ${b} = ${addBits(a, b)} (${toDec(a)} + ${toDec(b)} = ${toDec(addBits(a, b))})`)
);
// Result
// 0 + 0 = 0 (0 + 0 = 0)
// 0 + 1 = 1 (0 + 1 = 1)
// 1 + 0 = 1 (1 + 0 = 1)
// 1 + 1 = 10 (1 + 1 = 2)
// 00 + 10 = 10 (0 + 2 = 2)
// 01 + 00 = 01 (1 + 0 = 1)
// 10 + 00 = 10 (2 + 0 = 2)
// 10 + 01 = 11 (2 + 1 = 3)
// 10 + 10 = 100 (2 + 2 = 4)
// 11 + 00 = 11 (3 + 0 = 3)
// 11 + 01 = 100 (3 + 1 = 4)
// 11 + 10 = 101 (3 + 2 = 5)
// 11 + 11 = 110 (3 + 3 = 6)
// 101 + 001 = 110 (5 + 1 = 6)
// 1111 + 0011 = 10010 (15 + 3 = 18)
// 011111 + 111111 = 1011110 (31 + 63 = 94)
// 11011 + 00001 = 11100 (27 + 1 = 28)
// 11111111 + 00000001 = 100000000 (255 + 1 = 256)
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.