Skip to content

Instantly share code, notes, and snippets.

@terremoth
Created October 15, 2022 12:32
Show Gist options
  • Save terremoth/130be51f21d23d4f66b622e3294dcf65 to your computer and use it in GitHub Desktop.
Save terremoth/130be51f21d23d4f66b622e3294dcf65 to your computer and use it in GitHub Desktop.
Sum without "+" operator using bitwise
function soma(first, second) {
while (second != 0) {
var carry = first & second;
first = first ^ second;
second = carry << 1;
}
return first;
}
console.log(soma(10, 5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment