Skip to content

Instantly share code, notes, and snippets.

@diegocstn
Created March 12, 2017 17:44
Show Gist options
  • Save diegocstn/591d7a5f99236b6e99b4e98d83eba739 to your computer and use it in GitHub Desktop.
Save diegocstn/591d7a5f99236b6e99b4e98d83eba739 to your computer and use it in GitHub Desktop.
add two numbers without using arithmetic operators
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