In C programming language, bitwise operators are used to manipulate individual bits of data. Bitwise operators are applied to the binary representation of a data value. C provides six bitwise operators: &, |, ,̂ , <<, and >>.
& (bitwise AND) operator: The & operator returns 1 if both the bits in the corresponding positions of the operands are 1; otherwise, it returns 0.
unsigned char a = 0x0F; // 00001111
unsigned char b = 0x3C; // 00111100
unsigned char c = a & b; // 00001100
| (bitwise OR) operator: The | operator returns 1 if either of the bits in the corresponding positions of the operands is 1; otherwise, it returns 0.
unsigned char a = 0x0F; // 00001111
unsigned char b = 0x3C; // 00111100
unsigned char c = a | b; // 00111111
(̂bitwise XOR) operator: The ôperator returns 1 if the bits in the corresponding positions of the operands are different; otherwise, it returns 0.
unsigned char a = 0x0F; // 00001111
unsigned char b = 0x3C; // 00111100
unsigned char c = a ^ b; // 00110011
(bitwise NOT) operator: The operator is a unary operator that returns the complement of the bits in the operand. It converts all 0 bits to 1 and all 1 bits to 0.
unsigned char a = 0x0F; // 00001111
unsigned char b = ~a; // 11110000
<< (left shift) operator: The << operator shifts the bits of the left operand to the left by the number of positions specified by the right operand. The left operand is treated as an unsigned integer.
unsigned char a = 0x0F; // 00001111
unsigned char b = a << 2; // 00111100
>> (right shift) operator: The >> operator shifts the bits of the left operand to the right by the number of positions specified by the right operand. The left operand is treated as a signed integer.
signed char a = -16; // 11110000
signed char b = a >> 2; // 11111100
Bitwise operators can be used for a variety of purposes, such as setting or clearing individual bits in a bit field, extracting specific bit fields from a larger data structure, and performing binary arithmetic. They are also used in low-level programming, such as in device drivers and embedded systems, where direct manipulation of individual bits is necessary.