What this calculator does
A bitwise calculator runs a logic operation on the individual binary digits of two numbers, rather than on the numbers as a whole. AND, OR and XOR each compare the numbers bit by bit and build a new number from the outcome of each comparison; NOT flips every bit of a single number.
These operations sit underneath a lot of ordinary programming: masking specific bits out of a value, toggling flags, checking whether a number is even, and packing several small settings into one integer. Working through the binary by hand is slow and error-prone once numbers get past a handful of bits, which is what this tool is for.
The formula
Convert both integers to binary and line them up bit by bit. AND gives a 1 only where both bits are 1. OR gives a 1 where either bit is 1. XOR gives a 1 only where the bits differ. NOT takes a single number and flips every bit, shown here as an unsigned 32-bit result. The result is shown in both decimal and binary so you can check the working.
| Term | Meaning |
|---|---|
| AND | Bit is 1 only where both inputs have a 1 in that position. |
| OR | Bit is 1 where at least one input has a 1 in that position. |
| XOR | Bit is 1 where the two inputs differ, and 0 where they match. |
| NOT | Flips every bit of a single number; here shown as an unsigned 32-bit result. |
The inputs explained
| Field | What to enter |
|---|---|
| First integer | The first whole number, entered as an ordinary decimal integer. |
| Second integer (ignored for NOT) | The second whole number, ignored when the operation is NOT. |
| Operation | Which bitwise operation to apply to the two integers above. |
When to use it
Masking specific bits
ANDing a value against a mask such as 15 (binary 1111) isolates only the lowest four bits of a number, discarding everything above them, which is how many low-level formats extract a packed field.
Combining flags
ORing several power-of-two values together packs multiple true/false settings into a single integer, a pattern still used in permission systems and hardware registers.
Spotting differences
XORing two numbers highlights exactly which bits differ between them, which is why XOR shows up in checksums, simple encryption and toggling a bit on and off with a repeated operation.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
AND, OR and XOR of 255 and 15
The same two integers, 255 (binary 11111111) and 15 (binary 00001111), run through each operation in turn.
Questions
How is bitwise AND different from ordinary multiplication?
They can agree for single bits (0 and 1), but bitwise AND works position by position across the whole binary representation, not on the numbers as quantities, so AND-ing 6 and 3 gives 2, not 18.
What does XOR with the same number twice do?
It returns the original value, because XOR-ing a bit with itself always gives 0, leaving every bit unchanged the second time. This is the basis of simple bit-toggling and some lightweight encryption schemes.
Why does NOT produce such a large decimal number?
NOT flips every bit, including the leading zero bits that were not shown. This calculator treats the result as an unsigned 32-bit number, so flipping a small value produces a number close to 4.29 billion rather than a small negative one.
How is this different from a bit-shift or two's complement calculator?
A bitwise calculator combines or flips bits between numbers using AND, OR, XOR and NOT. A bit-shift calculator instead moves the bits of a single number left or right, and a two's complement calculator represents negative numbers in binary; the three cover different operations on binary data.
To shift the bits of a single number left or right instead of combining two numbers, see the bit-shift calculator. For representing negative numbers in binary, see the two's complement calculator.