I just learned some symbols that I haven't seen in C++ books, record it

One, << and >>: the one after cout and cin, but not the one after cout and cin here. They are the bitwise left-shift and right-shift operators, and their role is to shift the binary form of a number to the left or right.

To give two examples, 18 (binary form is 00010010) <<2 = 72 (binary form is 01001000, and the binary form of 18 is shifted two places to the left), 77 (binary form is 1001101) >> 3=9 (binary form For 0001001, the binary form of 77 is shifted two places to the right).

In fact, to put it bluntly, m<<n is m*(2 to the nth power), and m>>n is m/(2 to the nth power). Of course, m and n here are both integer variables. In addition, these two operators can save time. This method is very important in program optimization. For example, a*9 can be replaced by (a<<3)+a (note that "+" operation is better than "<<" operation takes precedence).


Second, arithmetic and &, arithmetic or |, arithmetic not ~, arithmetic Xor ^: these are very important binary operators, let’s take an example:

25 (binary is 00011001) & 19 (binary is 00010011) = 17 (binary is 00010001), the & operator is to compare the binary form of two integers bit by bit, only one of the two numbers is 1, the result is the same The bit is 1, the others are 0, that is, 0 is 0, no 0 is 1

25 (binary form is 00011001) | 19 (binary form is 00010011) = 27 (binary form is 00011011), the | operator is to compare the binary form of two integers bit by bit, only one of the two numbers is 0 , the bit of the result is 0, the others are 1, that is, 1 is 1, no 1 is 0

~ 19 (binary form is 00010011) = -20 (binary form is 10010100), uh (⊙﹏⊙), I didn't understand this for a long time, anyway, for a decimal number n, ~n=-n-1

25 (00011001 in binary form) ^ 19 (00010011 in binary form) = 10 (00001010), that is, the same is 0, the difference is 1


Third, the order of some operators (from high to low):

1. ()(parentheses) [ ](array subscript) .(member of class) ->(member of class pointed to)
2. !(logical negation) .(bit inversion) -(minus sign) ++(self-increment) --(self-decrement) &(address)
3. * (pointer) sizeof (length calculation)
4. *(multiply)/(divide) %(modulus)
5. +(plus) -(minus)
6. << (bit left shift) >> (bit right shift)
7. < (less than) <= (less than or equal to) > (greater than) >= (greater than or equal to)
8. == (equal) != (not equal)
9. & (arithmetic and)
10. ^ (arithmetic exclusive OR)
11. | (arithmetic or)
12. && (logical AND)
13. || (logical or)
14. ? :
15. =    +=   -=

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326026338&siteId=291194637