Home >Backend Development >C++ >What do & and | mean in C language?
The & (bitwise AND) and | (bitwise OR) operators in C language operate on integer binary bits bit by bit: the result of the & operation is 1 if and only if both bits are 1; | The result of the operation is 1 if and only if at least one bit is 1.
& and | operators in C language
& (bitwise AND)## The
#& operator ANDs the binary bits of two given integers bit by bit, and the result is 1 if and only if both corresponding bits are 1.Syntax:
result = x & y;
Example:
int x = 6; // 0b110 int y = 5; // 0b101 int result = x & y; // 0b100 (4)
| (Bitwise OR)
|Operator ORs the binary bits of two given integers bit by bit, and the result is 1 if and only if at least one corresponding bit is 1.Grammar:
result = x | y;
Example:
int x = 6; // 0b110 int y = 5; // 0b101 int result = x | y; // 0b111 (7)
Notes:
The above is the detailed content of What do & and | mean in C language?. For more information, please follow other related articles on the PHP Chinese website!