Skip to content

Instantly share code, notes, and snippets.

@cozzbie
Last active June 27, 2018 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cozzbie/eb9110d84a429d12d96067b114a08b22 to your computer and use it in GitHub Desktop.
Save cozzbie/eb9110d84a429d12d96067b114a08b22 to your computer and use it in GitHub Desktop.
Bitwise Addition
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