Aim To perform bitwise set and reset
Bitwise operations work directly on the binary representations of integers, allowing efficient data manipulation. Key operations include:
- Bitwise AND (&): Sets bits to 1 where both operands have 1.
- Bitwise OR (|): Sets bits to 1 if at least one operand has 1.
- Bitwise XOR (^): Sets bits to 1 where operands differ.
- Bitwise NOT (~): Inverts all bits.
- Left Shift (<<): Shifts bits to the left, effectively multiplying by 2.
- Right Shift (>>) : Shifts bits to the right, effectively dividing by 2.
- Setting a Bit: Alters a bit to 1 at a specific position.
- Resetting a Bit: Alters a bit to 0 at a specific position.
- Start
- Declare variables
aandb. - Input values for
aandb. - Perform Bitwise Operations:
- AND:
a & b - OR:
a | b - NOT:
~a - XOR:
a ^ b - Left Shift:
a << 1 - Right Shift:
a >> 2
- AND:
- Output results for each operation.
- End
- Start
- Declare variables
a,i,set, andreset. - Input
aand shift positioni. - Compute:
- Set Bit:
set = a | (1 << i) - Reset Bit:
reset = a & (~(1 << i))
- Set Bit:
- Output
setandresetresults. - End