Last active
June 27, 2018 07:20
-
-
Save cozzbie/eb9110d84a429d12d96067b114a08b22 to your computer and use it in GitHub Desktop.
Bitwise Addition
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
function add(a, b) { | |
if(b == 0) return a; | |
return add(a ^ b, (a & b) << 1); | |
} | |
add(4, 5) // 9 | |
function subtract(a, b) { | |
return (add(a, add(~b, 1))); | |
} | |
subtract(9, 2) // 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment