Value of ~5 shoud be 122

~5 = 1111010
which should be 64+32+16+8+0+2+0=122
The actual answer is -6 why?

consider this example:-

int a = 103;  // binary:  0000000001100111
int b = ~a;   // binary:  1111111110011000 = -104

You might be surprised to see a negative number like -104 as the result of this operation. This is because the highest bit in an int variable is the so-called sign bit. If the highest bit is 1, the number is interpreted as negative
This encoding of positive and negative numbers is referred to as two’s complement. For more information, see the Wikipedia article on two’s complement.

Thank You, PLease help me close this thread by sending the rating link.

you must have an option to mark it as resolved at your end. you’ll get a rating link there

This button doesn’t work in my profile. I have reported it to the support team again and again. Sorry for this inconvenience.

it’s okay .i ll mark it resolved :slight_smile:

Yes Please do it, thank you.

1 Like