Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created November 23, 2018 22:43
Show Gist options
  • Save miladvafaeifard/d00c3660421f15c83aa0bce7e1991ac8 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/d00c3660421f15c83aa0bce7e1991ac8 to your computer and use it in GitHub Desktop.
~ NOT
let num = 2;
console.log(~num); // -3
// how it works
// first we should know binary code, convert 2 to 0010 and flip it to 1101 (-2), and then add 1 to it, the result is -3.
num = -2;
conosle.log(~num); // 1
// -2 + 1 = -1 -> 1110 then filp it to 0001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment