Tag: difference between logical inversion and bitwise Inversion
Http://blog.csdn.net/pipisorry/article/details/36517411
Bitwise inversion "~" : Change the bitwise value to 1 to 0 and 1 to 0.
The logic is not "!" : Logic inversion, false to true, true to false, in C, as long as it is not 0 is true
Bytes ------------------------------------------------------------------------------------------------------------------------------
So
! The value of 5 is 0.
~ Bitwise Inversion
5 binary 00000101, decimal 11111010, representing-6
So ~ 5-6
~ Is bitwise inversion, for example, integer 3, the binary form is
00000000000000000000000000000011, which is after bitwise Inversion
11111111111111111111111111111100
! Yes logic No. After a non-zero number is obtained, it is 0. The above 3 is used! Followed by 0
All numbers are not 0! 0 after Operation
Use! And ~ The result value is the same.
The bitwise result of all positive integers is itself + 1 negative.
Bitwise inversion of all negative integers is the absolute value of itself + 1
The bitwise result of zero is-1.
Ref:
Http://blog.csdn.net/pipisorry/article/details/36517411
Http://blog.csdn.net/xiexievv/article/details/8124108