Bitwise Operators in C

Bitwise operators in C are operators that perform operations on the individual bits of integer operands. These operators are useful for manipulating binary data, such as in low-level programming, cryptography, and digital signal processing.

Here are the bitwise operators in C:

1. `&` (bitwise AND): This operator performs a bitwise AND operation on the corresponding bits of two integer operands. The result is a new integer that has a 1 in each bit position where both operands have a 1.

For example:

int a = 0x0F; // 00001111
int b = 0x03; // 00000011
int c = a & b; // 00000011

Here, the bitwise AND operation between `a` and `b` produces the result `c = 0x03`, which has a 1 in the last two bit positions where both `a` and `b` have a 1.

2. `|` (bitwise OR): This operator performs a bitwise OR operation on the corresponding bits of two integer operands. The result is a new integer that has a 1 in each bit position where either operand has a 1.

For example:

int a = 0x0F; // 00001111
int b = 0x03; // 00000011
int c = a | b; // 00001111

Here, the bitwise OR operation between `a` and `b` produces the result `c = 0x0F`, which has a 1 in all bit positions where either `a` or `b` has a 1.

3. `^` (bitwise XOR): This operator performs a bitwise XOR (exclusive OR) operation on the corresponding bits of two integer operands. The result is a new integer that has a 1 in each bit position where the operands have different values.

For example:

int a = 0x0F; // 00001111
int b = 0x03; // 00000011
int c = a ^ b; // 00001100

Here, the bitwise XOR operation between `a` and `b` produces the result `c = 0x0C`, which has a 1 in the third and fourth bit positions where `a` and `b` have different values.

4. `

` (bitwise NOT): This operator performs a bitwise NOT operation on an integer operand. The result is a new integer that has the complement of each bit in the operand.

For example:

int a = 0x0F; // 00001111
int b =

a;   // 11110000

Here, the bitwise NOT operation on `a` produces the result `b = 0xF0`, which has the complement of each bit in `a`.

5. `<<` (left shift): This operator shifts the bits of an integer operand to the left by a specified number of positions. The result is a new integer that has the bits shifted to the left, with zeros inserted in the vacated bit positions. For example:

int a = 0x0F; // 00001111
int b = a << 2; // 00111100

Here, the left shift operation on `a` by 2 positions produces the result `b = 0x3C`, which has the bits of `a` shifted to the left by two positions, with zeros inserted in the last two bit positions.

6. `>>` (right shift): This operator shifts the bits of an integer operand to the right by a specified number of positions. The result is a new integer that has the bits shifted to the right, with zeros inserted in the vacated bit positions for unsigned operands, and the sign bit extended in the vacated bit positions for signed operands.

For example:

int a = 0x0F; // 00001111
int b = a >> 2; // 00000011

Here, the right shift operation on `a` by 2 positions produces the result `b = 0x03`, which has the bits of `a` shifted to the right by two positions, with zeros inserted in the first two bit positions.