Math calculator

Bitwise Calculator

Every operation, with its truth table and the bits.

Bit by bit, with the truth table

The width matters — NOT depends on it.

AND at 8 bits

0000 1000

Which is 8 in decimal, or 0x08 in hex.

Bit by bit

A       0000 1100
B       0000 1010
AND     0000 1000
The truth table for AND, applied to every bit position independently.
ABOut
000
010
100
111

Result

0000 1000

8 bits

Decimal

8

unsigned

Hex

0x08

four bits per digit

  • AND is how a mask works: a 1 in the mask keeps the bit, a 0 clears it. Testing whether a single bit is set is an AND with a one-bit mask.
  • Bitwise operations act on each bit position independently — there are no carries, so unlike addition they cannot propagate.

Each bit position is independent — there are no carries, so unlike addition these cannot propagate.

What this tool shows

Bitwise operations act on each bit position independently — there are no carries, so unlike addition they cannot propagate. And the register width matters: the same value inverts differently at 8 bits and at 32.

  • AND, OR, XOR and NOT
  • NAND, NOR and XNOR
  • The truth table for each
  • Why the register width matters
  • What each operation is used for
  • Why NAND alone is enough for everything
Seven operations Truth tables Four widths Bit-by-bit view

Choose the width — it changes what NOT returns.

Updated 7 September 2026 · Works in any browser, no installation

Each bit position is handled independently. 1100 AND 1010 is 1000, because only the fourth column has a 1 in both. There are no carries, so unlike addition a bitwise operation cannot propagate — and that is what makes it a single fast instruction.

At a glance

Formula shown
Each operation applies its truth table to every bit position independently. AND gives 1 only when both bits are 1; OR when either is; XOR when exactly one is; NOT inverts within the register width.
Scenario support
Working with flags and masks; reading a hardware register; understanding a permissions value; debugging a bit manipulation.
Educational estimate
Planning support from the values you enter — not professional advice.

Why the width matters

For AND, OR and XOR the width is cosmetic. For anything involving inversion it is not.

NOT flips every bit within the register. Inverting 12 gives 243 at 8 bits and 4294967283 at 32 — and both are correct. The operation is not defined without knowing how many bits there are.

The same applies to NAND, NOR and XNOR, since each is an inversion of something else.

This is a real source of bugs when code moves between types. Inverting a value stored in a smaller type and assigning it to a larger one gives a different answer from inverting it after the conversion, and neither is wrong — they are answers to different questions.

This page makes the width an explicit choice rather than picking one silently.

What each one is for

Each operation has a job it is reached for, and knowing which makes bit manipulation readable.

AND masks. A 1 in the mask keeps a bit, a 0 clears it. Testing a single flag is an AND with a one-bit mask.

OR sets. It turns bits on without disturbing the others, which is how flags are combined into a single value.

XOR toggles, and detects difference. It is zero exactly when the two operands are identical.

NOT inverts, and is usually seen building a mask: NOT of a bit pattern gives the mask that clears exactly those bits.

NAND and NOR are rarely written in software and are the fundamental gates in hardware, for the reason below.

XOR is special

XOR has a property the others lack: it is its own inverse. Apply it twice with the same value and you get back where you started.

That single fact accounts for most of what XOR is used for.

Toggling. XOR with a mask flips exactly those bits, and doing it again restores them.

Swapping without a temporary. Three XORs exchange two variables. It is a party trick rather than good practice — a compiler produces better code from an ordinary swap — but it demonstrates the property.

The one-time pad. XOR a message with a truly random key of the same length and the result is provably unbreakable. XOR it again with the same key and the message returns. It is the only cipher with a proof of perfect secrecy, and the difficulty is entirely in distributing keys as long as the messages.

Parity and error detection. XOR of all the bits is the parity bit, and RAID storage reconstructs a lost drive by XOR-ing the others.

NAND builds everything

NAND is functionally complete: every other logic operation can be built from it alone.

NOT is a NAND with both inputs tied together. AND is a NAND followed by that NOT. OR is a NAND of two NOTs. From there, everything.

So an entire processor can be made from nothing but NAND gates — and in a real sense one is. In CMOS, NAND and NOR are the cheapest gates to fabricate, and AND and OR are built from them rather than the other way round.

NOR is functionally complete too, and it has a claim to fame: the Apollo Guidance Computer, which flew to the Moon, was built entirely from NOR gates — about 2,800 of them in a single circuit type.

Masks and flags

The commonest practical use of bitwise operations is packing several yes/no values into one number.

Set a flag: value OR mask. Clear one: value AND NOT mask. Toggle one: value XOR mask. Test one: value AND mask, and check whether the result is non-zero.

Those four idioms cover nearly all bit manipulation in practice, and they are worth recognising on sight.

Unix file permissions are the familiar example: 755 in octal is three groups of three bits, and chmod is doing exactly these operations.

Network subnet masks are the same idea. An address AND a mask gives the network portion, which is how routing decides where a packet goes.

Sources and methodology

Bitwise logic is standard; these are the references.

Method. The register width is taken as an input rather than assumed, because NOT and the inverted operations genuinely depend on it — inverting 12 at 8 bits gives 243 and at 32 bits gives 4294967283, and both are correct for their width. All arithmetic is on BigInt, so a 64-bit operation is exact rather than being done in a double. The suite re-derives AND, OR and XOR against JavaScript’s own operators at 32 bits. That engine is verified on every change against 90 hand-written assertions, including that AND, OR and XOR match JavaScript’s own operators, and that XOR applied twice with the same key returns the original on four hundred generated pairs. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Bit ShiftLeft, logical right, arithmetic right and rotate — with the two right shifts kept apart, because they differ for negatives and one of them floors rather than truncating.
Binary ArithmeticAdd, subtract, multiply and divide in binary, octal or hex — with the carry row shown, and what a processor actually does instead of subtracting.
Twos ComplementTwo's and one's complement at 8 to 64 bits, with the signed range and its asymmetry — and why negating the minimum gives back the minimum.
Floating PointThe exact decimal value a double actually stores, written out in full — which is why 0.1 + 0.2 does not equal 0.3 in almost every programming language.
ModuloAll three conventions at once, because −7 mod 3 is −1 in JavaScript and 2 in Python and a page that gives only one of those is wrong for half its readers.
Luhn AlgorithmValidate a number or generate its check digit, with the doubling shown — and a live test of whether it catches a transposition, which is what a digit sum cannot.

More in Math, or browse all calculators.

Read the guide

Shifting is the other half of bit manipulation — the Bit Shift Calculator covers the two right shifts and why both exist.

Educational use disclaimer

This is an educational tool. The register width matters: NOT and the inverted operations give different answers at different widths.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the bitwise page taking the register width as an explicit input, since NOT and the inverted operations genuinely depend on it — inverting 12 gives 243 at 8 bits and 4294967283 at 32, and both are correct for their width.
  2. Explains what each operation is reached for rather than only what it computes: AND masks, OR sets, XOR toggles and detects difference, and NAND alone can build every other one.
  3. Notes that XOR is its own inverse, which is why it underlies toggling, the one-time pad and RAID reconstruction.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.