0
How tilde operator works in C?
~5 of is giving -6 as output. Pls explain how. https://code.sololearn.com/cwI867Lo4KqZ/?ref=app https://code.sololearn.com/cwI867Lo4KqZ/?ref=app
1 Answer
+ 1
The binary representation of 5 is 00000101. If you invert it (this it what tilde does) you will have 11111010. This is the binary representation of -6.
Hot to get the binary of a negative number. Do the binary of the positive (6): 000000110, Invert all digits -> 11111001 and add one (the plus-one-complement) and you get 11111010.