0

~0 value

I got the following question : What is the value of x ? x = 1 - (-1 == ~0) The answer was 0. I don't understand why the 1's complement (if "~" is 1's complement) of 0 is -1, what notion I've missed to understand this question ? Thanks for constructive answers.

24th Sep 2020, 2:08 PM
#D.D.
1 Answer
+ 2
0 in eight bits is 00000000 and when you inverted it become 11111111 since the msb is the sign and when its 1 then the number is negative so -128+64+32+16+8+4+2+1 which equal - 1 and as a rule ~var=-(var+1)
24th Sep 2020, 2:12 PM
Ruba Kh
Ruba Kh - avatar