Assume your environment is 32-bit and int is 4 bytes. 0 is equivalent to 00000000 00000000 00000000 00000000, '~' bitwise inversion , and we get 11111111 11111111 11111111 11111111 . Also, what is 0b11? I don't think I've seen this way of writing before?
Since 0b11 is a binary number, the answer is obvious. The result of ~0 is 1, 0b11 is ANDed with 1, and the result remains unchanged, so the result is 3, the decimal result of 0b11.
Assume your environment is 32-bit and int is 4 bytes. 0 is equivalent to
00000000 00000000 00000000 00000000
, '~' bitwise inversion , and we get11111111 11111111 11111111 11111111
. Also, what is
0b11
? I don't think I've seen this way of writing before?Because ~ is bitwise inversion. If all are 0, if you negate each one, they will all be 1
Since
0b11
is a binary number, the answer is obvious. The result of~0
is 1,0b11
is ANDed with 1, and the result remains unchanged, so the result is 3, the decimal result of0b11
.0b11
is actually binary literal.But this is a gcc extension. If you use vc++, it can only be used in 2015 Preview.