Bitwise Operations: AND, OR, XOR, Shifts Explained
Learn bitwise AND, OR, XOR, NOT, and bit shifts. Practical examples for flags, masks, permissions, and performance tricks in low-level code.
Published:
Tags: developer-tools, number-systems, bitwise
Bitwise Operations Guide: AND, OR, XOR, Shifts for Developers Bitwise operations manipulate individual bits in an integer. They're fast (single CPU instruction), compact, and show up constantly in systems programming, embedded development, network protocol parsing, and performance-critical code. If you write C, Go, Rust, Python, or even JavaScript, you'll encounter them. This guide covers every major bitwise operator with practical examples you can use immediately. --- Binary Refresher All bitwise operations work on the binary representation of integers. A quick reminder: For these examples we'll use 4-bit or 8-bit integers for clarity. Real integers are 32 or 64 bits; the principles are identical. --- AND ( & ) AND returns 1 only where both operands have a 1 bit. Primary use: masking —…
All articles · theproductguy.in