Created
October 15, 2022 12:32
-
-
Save terremoth/130be51f21d23d4f66b622e3294dcf65 to your computer and use it in GitHub Desktop.
Sum without "+" operator using bitwise
This file contains hidden or 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 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