0
#include <iostream> using namespace std; int main() { int x=~1; cout<<x; }
the answer is -2 ,someone who understand why -2 help me to understand
7 odpowiedzi
+ 8
I'm not good at signed conversion of decimal value to binary value, but I can tell that the inversion of bits of binary value for 1 will result in -2.
+ 7
The ~ operator is bitwise NOT, it inverts the bits in a binary number:
NOT 011100 = 100011
+ 4
That is not a destructor sign. ~ is the bitwise operator for NOT.
1 in binary is 00000000000000000000000000000001, ~1 will be 11111111111111111111111111111110 which is -2
+ 2
7 in binary will be 00111. When NOT 7 it becomes 11000. If u know about the twos complement, 11000 is the negative of 01000 which is 8. Thus, ~7 will results a -8.
+ 1
so why -2
+ 1
I tested in a compiler x=~7 it give me -8 so increment 1 and assign -
0
~(destructor ) what I know, so why increment 1 and assign -