Bitwise operators allow processing of individual bits within a byte or larger unit of data: any bit or bits can be cleared, set, or inverted. You can also shift the bit pattern of an integer to the right or left.
1. "&"
Bitwise AND operation, perform "AND" operation based on binary bits. Operation rules:
0&0=0; 0&1=0; 1&0=0; 1&1=1;
2, "|"
Bitwise OR operator, perform "OR" operation based on binary bits. Operation rules:
0|0=0; 0|1=1; 1|0=1; 1|1=1;
3, "^"
XOR operator, performs "XOR" operation based on binary bits. Operation rules:
0^0=0; 0^1=1; 1^0=1; 1^1=0;
4, "~"
Negation operator, performs "inversion" operation based on binary bits. Operation rules:
~1=0; ~0=1;
5, "<<"
Binary left shift operator. Shift all the binary bits of an operand to the left by a certain number of bits (the left bit is discarded and the right bit is filled with 0).
A << 2 will get 240, which is 1111 0000
6, ">>"
Binary right shift operator. Shift all the binary digits of a number to the right by a certain number of bits. Positive numbers are padded with 0s on the left, negative numbers are padded with 1s on the left, and the right sides are discarded.
A >> 2 will get 15, which is 0000 1111
The above is the detailed content of c language bit operators. For more information, please follow other related articles on the PHP Chinese website!