Codacoda
Back to Academy

bitwise operations

AND, OR, XOR, NOT

The four fundamental bitwise operations work on individual bits of integers. AND (&) returns 1 only when both bits are 1, OR (|) returns 1 when either bit is 1, XOR (^) returns 1 when bits differ, and NOT (~) flips every bit. These operations form the foundation of all bit manipulation techniques.

Use Cases

  • Permission flags and access control systems
  • Combining and intersecting feature flag sets
  • Low-level hardware register manipulation
  • Cryptographic primitives and hash functions

Complexity Analysis

MetricBestAverageWorst
TimeO(1)O(1)O(1)
SpaceO(1)

Visualization

Operands50000010176543210300000011
Speed:1x
Operands: 5 (00000101) and 3 (00000011)Step 1 / 5

Implementation

Output

Click "Run Code" to see output...