Back to Academy
bitwise operations
Check/Set/Clear/Toggle Bit
The four fundamental single-bit operations let you inspect and modify individual bits at any position. Check uses AND with a shifted 1, Set uses OR, Clear uses AND with NOT, and Toggle uses XOR. These are the building blocks of all higher-level bit manipulation.
Use Cases
- •Managing boolean arrays compactly with a single integer
- •Setting and reading hardware control register flags
- •Toggling feature states without branching
- •Bitmap-based memory allocators
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(1) | O(1) | O(1) |
| Space | O(1) | ||
Visualization
Implementation
Output
Click "Run Code" to see output...