Created
October 25, 2016 19:05
-
-
Save rwaldron/feed80026adcb1eca0b70e35b94618c9 to your computer and use it in GitHub Desktop.
Full Adder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fullAdder = (a, b, c) => [(a ^ b) ^ c, ~(~(a & b) & ~((a ^ b) & c))]; | |
[ | |
{ args: [0, 0, 0], expect: {sum: 0, carry: 0}}, | |
{ args: [0, 0, 1], expect: {sum: 1, carry: 0}}, | |
{ args: [0, 1, 0], expect: {sum: 1, carry: 0}}, | |
{ args: [0, 1, 1], expect: {sum: 0, carry: 1}}, | |
{ args: [1, 0, 0], expect: {sum: 1, carry: 0}}, | |
{ args: [1, 0, 1], expect: {sum: 0, carry: 1}}, | |
{ args: [1, 1, 0], expect: {sum: 0, carry: 1}}, | |
{ args: [1, 1, 1], expect: {sum: 1, carry: 1}}, | |
].forEach(test => { | |
let result = fullAdder(...test.args); | |
console.log(result[0] === test.expect.sum); | |
console.log(result[1] === test.expect.carry); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment