So as I was reading about ~
,
Performs the NOT operator on each bit.
So I tried:
0 = 00000000000000000000000000000000
so ~0 should be
~0 = 11111111111111111111111111111111
But when I tried, it returns -1
. Isn't 11111111111111111111111111111111
is 4294967295
in decimal?
It's interpreted as a signed integer, and in two's complement, an integer with all bits 1 is -1
.
Only if the type is unsigned. Signed integers use the topmost bit as a negation flag - and thus setting it to 1 results in a negative number. See Two's Complement.
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