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

3rd Mar 2019, 8:32 PM
HITESH AHUJA
HITESH AHUJA - avatar
1 Odpowiedź
+ 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.
3rd Mar 2019, 8:40 PM
nobody