Ques 12 in bitmasking quiz

int x =~10; how is the value of x “-11”?

@aiman.mumtaz

  1. X is a int and not unsigned int.
    ~10 inverts the bits of 10 ie. 1010 to 0101
    now this is a negative value to get its magnitude we invert the bits and add 1 i.e twos complement and put the sign
    -> 0101 -> 1010 + 1 --> 1011 and sign is negative therefore ans is -11