Time/Numbers
Bitwise Operations
AND/OR/XOR/NAND/NOR/XNOR/NOT and shifts on integers of a given width (8/16/32/64 bits) in any number base.
(shift amount, decimal number)
Bitwise operations work directly on a number's individual bits rather than its value as a whole — the basis for permission flags, network protocols, and low-level optimization.
How to use it
- Enter one or two numbers in any base (binary, hex, decimal) and pick an operation (AND, OR, XOR, NAND, NOR, XNOR, NOT, or a shift).
- Pick a bit width (8/16/32/64 bits) — it affects how NOT and shifts behave at the number's boundaries.
- The result is shown instantly in several number bases for easy comparison.
Common uses
- Working with permission or setting flags packed into a single number (file system access rights, for example).
- Debugging a network protocol or binary format where fields are packed at the individual-bit level.
- A teaching example for understanding binary number representation and operations on it.
Things to keep in mind
The result of NOT and shifts depends on the chosen bit width — the same number gives a different result at 8-bit versus 32-bit width because of the different number of bits involved.
XOR is often used to toggle a flag — applying XOR twice with the same value returns the original.
Article about this tool: Bitwise operations: how AND, OR, and XOR work at the bit level
Frequently asked questions
What's the difference between AND, OR, XOR, NAND, NOR, XNOR, and NOT?
AND gives 1 only when both bits are 1, OR gives 1 when at least one is 1, and XOR gives 1 when the bits differ. NAND/NOR/XNOR are their negations, and NOT inverts every bit of a single operand.
How is the bit width and sign of a number handled?
Choose a width of 8/16/32/64 bits — operations and shifts happen within that range. Negative numbers are represented in two's complement, so the result of NOT or a shift can look unexpected if you're used to decimal notation.
What's the difference between a left shift and a right shift?
A left shift (<<) adds zeros on the right, effectively multiplying by 2 raised to the shift amount. A right shift can be logical (adds zeros on the left) or arithmetic (preserves the sign bit) — the type depends on the selected mode.
Why does "if (a & b == c)" often not work as expected?
In most languages, the comparison operator == has higher precedence than the bitwise & operator, so the expression evaluates as "a & (b == c)" rather than what the author usually intends. Always wrap bitwise operations in explicit parentheses to avoid this trap.
Why use bitwise flags instead of separate boolean variables?
A set of flags packed into a single number is more compact to store and transmit (e.g. in network protocols or file formats), and checking or changing a specific flag with AND/OR/XOR is a single fast operation.