What does "&", "|", "^" mean in code and how do I set bit 5?
Bitwise operators are the foundation of many low-level tricks: permission masks (Unix `chmod`), bit flags, numeric optimizations (`x & 1` instead of `x % 2`), parsing network protocols (TCP flags, RGBA colors), memory management.
Type two numbers into A and B (as dec, hex 0x, bin 0b, oct 0o, auto-detected), pick a width (8-bit, 16-bit, 32-bit, 64-bit) and watch every operation live: AND, OR, XOR, NOT, shifts, rotations, popcount, lowest set bit.
Every result shown in a bit grid (click a bit to flip), in binary, dec (signed + unsigned), hex and oct. Computed with BigInt so 64-bit values work correctly even above `Number.MAX_SAFE_INTEGER`.
How to use it
- Pick a width: 8 / 16 / 32 / 64 bits. Decides how many bits the operand has and how overflow is detected.
- Enable Signed if you want values interpreted as two's complement (e.g. -1 in 8-bit = 0b11111111).
- Enter A and B. Accepts every format: `255`, `0xFF`, `0b11111111`, `0o377`. Format auto-detected from the prefix.
- Click a bit in the grid to flip it (toggle). Operations recompute immediately, all 12+ results update live.
- For shifts and rotations set n with the slider. For single-bit ops (set/clear/toggle/test) set bit N.
- "Highlight differing bits" shows in orange which bits the operation changed, perfect for seeing what `XOR` or `<<` actually does.
- Copy any result in any format (BIN, HEX, OCT, DEC) with one click.
When this is useful
Real situations where you need to know bitwise operations:
- Unix file permissions: `chmod 755` is a bitmask. `rwxr-xr-x` = `0b111101101` = 0o755 = 493 dec. Each bit is one flag (read/write/execute × owner/group/other).
- TCP/IP flags: the TCP header has 9 flag bits (SYN, ACK, FIN, RST, PSH, URG...). A parser decodes them with masks: `flags & 0x01` is FIN, `flags & 0x02` is SYN, etc.
- RGBA colors: 32-bit packs 4 channels of 8 bits each. `red = (color >> 24) & 0xFF`, `green = (color >> 16) & 0xFF`, and so on.
- Configuration flags: C/Rust libraries pass dozens of options as a single int. `OPT_ASYNC | OPT_VERBOSE | OPT_RETRY`. Check: `if (opts & OPT_ASYNC)`.
- Hash functions and crypto: implementations of MD5, SHA, AES use rotations (`ROL`, `ROR`), XORs and shifts. Usually 32-bit.
- Bitmap indexes in databases: Postgres, Oracle, MySQL use bitwise ops for filtering.
- Hardware GPIO: Arduino, ESP32, Raspberry Pi control pins with `PORTB |= (1 << 5)`. Each bit = pin state.
- Network address masks: `192.168.1.0/24` is mask `0xFFFFFF00`. To check if an IP is in the network: `(ip & mask) == network`.
- Algorithms: bitset as a compact set, Brian Kernighan for popcount, Sieve of Eratosthenes on bits, Fenwick tree.
To convert between number bases, see our number base converter. For byte size conversions, see file size converter.