How does ~ operator work in c?
can anyone explain the following code?
main()
{
printf("%d",~5);
}
output is -6
5 is (probably) a 32-bit signed integer with bit representation 0x00000005, or in binary:
0b00000000000000000000000000001010
~5 is the bitwise NOT of 5, which will be 0xFFFFFFFA, or in binary:
0b11111111111111111111111111110101
Using two's complement, that is -6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With