Bitwise Calculator

Compute AND, OR, XOR and NOT on integers in decimal, hex or binary.

Free bitwise calculator. Enter two integers in decimal, hex or binary and compute AND, OR, XOR or NOT, with the result shown in binary, hex and decimal, masked to a chosen 8, 16, 32 or 64-bit width. Runs in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What do AND, OR and XOR do bit by bit?

AND sets a result bit to 1 only if both input bits are 1. OR sets it if either input bit is 1. XOR sets it if exactly one input bit is 1. NOT flips every bit of a single operand.

A bitwise calculator applies Boolean logic to each pair of bits in two integers. These operations are the foundation of flags, bitmasks, permissions, checksums and low-level protocol work. This tool accepts decimal, hex or binary input and shows the result in all three bases.

How it works

Each operation compares the operands bit by bit:

  • AND (&) — result bit is 1 only when both input bits are 1. Used to mask/clear bits.
  • OR (|) — result bit is 1 when either input bit is 1. Used to set bits.
  • XOR (^) — result bit is 1 when the input bits differ. Used for toggling and parity.
  • NOT (~) — flips every bit of operand A.

Because NOT and signed values depend on register size, the result is masked to your chosen width with mask = (1 << width) - 1. So NOT of an 8-bit value inverts exactly 8 bits.

Example

With A = 0b1100 (12) and B = 0b1010 (10):

  • A AND B = 0b1000 = 8
  • A OR B = 0b1110 = 14
  • A XOR B = 0b0110 = 6
  • NOT A (8-bit) = 0b11110011 = 243

Notes

Common idioms: set bit n with x | (1 << n), clear it with x & ~(1 << n), toggle it with x ^ (1 << n), and test it with x & (1 << n). The width selector lets you reproduce the exact wraparound behaviour of a fixed-size register.

Real-world bitwise operation patterns

These four operations appear in almost every codebase that deals with hardware, protocols, or compact data storage:

Permission flags Unix file permissions (chmod 755) encode three groups of three bits: read (4), write (2), execute (1). The number 755 in octal means owner=7 (rwx), group=5 (r-x), others=5 (r-x). Testing whether the owner has write permission: mode & 0b010000000 (or mode & 0o200).

Colour channels A 32-bit ARGB pixel stores four 8-bit channels in one integer. Extracting the red channel: (pixel >> 16) & 0xFF. Compositing two colours at 50% alpha involves per-channel blending with masks and shifts.

Network protocol headers The IPv4 header packs flags and fragment offset into 16 bits. The “don’t fragment” flag is bit 14: (flags_and_offset >> 14) & 1. The fragment offset is bits 0–12: flags_and_offset & 0x1FFF. These are the exact bitwise expressions you see in network parsing code.

XOR swap and cipher operations The classic variable swap without a temporary: a ^= b; b ^= a; a ^= b; works because XOR with the same value twice is a no-op. XOR ciphers and the ChaCha20 stream cipher both rely on XOR’s self-inverse property. In storage, RAID parity is computed as a running XOR of the data drives.

Operator precedence note

In C, C++, Java, and JavaScript, bitwise operators have lower precedence than comparison operators. A very common bug is writing if (x & mask == 0) when you mean if ((x & mask) == 0). Always parenthesise bitwise expressions when mixing them with comparisons. This calculator evaluates the operation directly so there is no precedence ambiguity, making it useful for quickly checking what an expression should produce before writing the code.