Posts

Showing posts with the label Bitwise

Bitwise Operators in C ++

Bitwise Operators in C++ Bitwise operators in C++ work directly on the individual bits of integer data types (like int, char, short, long, etc.). They manipulate the binary representation of these values. Here's a breakdown of common bitwise operators: 1. Bitwise AND (&)  * Purpose: Performs a logical AND operation on corresponding bits of two operands.  * Result: 1 only if both corresponding bits are 1, otherwise 0.    int a = 5;     // Binary: 0101 int b = 3;     // Binary: 0011 int c = a & b; // Binary: 0001 (Decimal: 1)  2. Bitwise OR (|)  * Purpose: Performs a logical OR operation on corresponding bits of two operands.  * Result: 1 if at least one of the corresponding bits is 1, otherwise 0.    int a = 5;     // Binary: 0101 int b = 3;     // Binary: 0011 int c = a | b; // Binary: 0111 (Decimal: 7)  3. Bitwise XOR (^)  * Purpose: Performs a logical XOR (exclusi...