Created
March 12, 2017 17:44
-
-
Save diegocstn/591d7a5f99236b6e99b4e98d83eba739 to your computer and use it in GitHub Desktop.
add two numbers without using arithmetic operators
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(x, y) { | |
while (y != 0) { | |
const carry = x & y; | |
x = x ^ y; | |
y = carry << 1; | |
} | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment