+ 2

# Why negation of 20 is equal to -21 (~20 = -21)?

Can any body please explain me why negation of 20 is equals to -21?

3 Answers

+ 4

The tilde (~) is the bitwise NOT operator, not a negator. For that, just use a negative sign (-).
The bitwise NOT operator it stated to "find the complement of an integer" by inverting the bits of a number. That is, converting it to binary and swapping all the 1's and 0's. Read more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT (although written for javascript specifically, the same concepts here work across many languages)

+ 3

https://www.sololearn.com/learn/4076/?ref=app
or ~(a)= -(a+1)
for ex 00000000 11111111
first four ones reprsent negative sign and remain represent 1 in binary format

0

Thank you.