Created
November 23, 2018 22:43
-
-
Save miladvafaeifard/d00c3660421f15c83aa0bce7e1991ac8 to your computer and use it in GitHub Desktop.
~ NOT
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
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