Bitwise Calculator

Run bitwise operations on two integers and see the result in decimal, hex, octal, and grouped binary at once. Supports AND, OR, XOR, NOT, NAND, NOR, XNOR, and left/right shifts, at 8, 16, 32, or 64-bit width. Enter operands in any base — decimal, 0x hex, 0b binary, or 0o octal — and the operands and result are shown in all four. Calculated with exact 64-bit precision in your browser.

How to use the Bitwise Calculator

Enter operand A, choose an operation, and (for everything except NOT) enter operand B. Each operand can be written in any base: plain digits for decimal, a 0x prefix for hexadecimal, 0b for binary, or 0o for octal — so you can mix 0xFF with 15 freely. The result appears immediately in decimal, hex, octal, and binary, with the binary grouped into nibbles or bytes for readability. The operands are shown the same way so you can line up the bits and see exactly what the operation did.

The bit width matters because it sets the mask. At 8-bit, results wrap to eight bits and NOT 0 is 0xFF; at 32-bit the same input gives 0xFFFFFFFF. Pick the width that matches your target — a byte, a 16-bit register, a 32-bit int, or a 64-bit value — and the calculator masks every result to that size. For shifts, operand B is the shift amount; left shifts drop bits that overflow the width, and right shifts are logical, filling with zeros, since the values are treated as unsigned within the chosen width.

Bitwise operations, explained

Bitwise operations work on the individual binary digits of an integer rather than its numeric value. AND sets a result bit only where both inputs have a 1, which makes it the tool for masking — clearing every bit except the ones you care about. OR sets a bit where either input has a 1, used to turn flags on. XOR sets a bit where the inputs differ, which is how you toggle bits and the basis of simple checksums and ciphers. NOT flips every bit. NAND, NOR, and XNOR are the negations of AND, OR, and XOR — NAND in particular is famous as a universal gate from which all other logic can be built.

Shifts move bits left or right. A left shift by n multiplies by 2ⁿ (until bits overflow the width), and a right shift by n divides by 2ⁿ, discarding the low bits. Shifts are the fast path for multiplication and division by powers of two and for packing several small fields into one integer. The subtlety is what fills the vacated bits and what happens to bits pushed past the edge — which depends entirely on the width and on whether the value is treated as signed or unsigned. This calculator treats operands as unsigned within the selected width, so right shifts are logical (zero-filled) and overflow simply wraps, which is the most predictable behaviour for bit manipulation.

Width is the concept that ties it together. A CPU register, a network protocol field, a permission bitmask, or a color channel each has a fixed number of bits, and the same operation can give different results at different widths because of how the result is truncated. Seeing the operands and result side by side in binary, hex, and decimal makes the abstract concrete: you can watch a mask clear the high nibble, a shift slide a value into position, or an XOR toggle exactly the bits that differ — which is why a bitwise calculator is a staple for embedded, graphics, networking, and low-level systems work.

Common use cases

  • Bit flags. Combine, set, clear, and test permission or option bitmasks.
  • Embedded and registers. Work out register values and masks for hardware programming.
  • Networking. Apply subnet masks and pack protocol fields into fixed-width integers.
  • Learning and debugging. See an operation's effect on individual bits across bases.

Frequently asked questions

What number formats can I enter?

Decimal (plain digits), hexadecimal with a 0x prefix, binary with 0b, and octal with 0o. You can mix formats between the two operands, and a leading minus sign is accepted and stored as its two's-complement value within the chosen width.

Why does the result depend on the bit width?

Every result is masked to the selected width. NOT 0 is 0xFF at 8-bit but 0xFFFFFFFF at 32-bit, and left shifts discard bits that overflow the width. Pick the width that matches your target — a byte, register, or 32/64-bit integer.

Are right shifts arithmetic or logical?

Logical. Operands are treated as unsigned within the chosen width, so a right shift fills the vacated high bits with zeros rather than the sign bit. This is the most predictable behaviour for bit manipulation.

Does it handle 64-bit values accurately?

Yes. Calculations use arbitrary-precision big integers, so 64-bit operands and results are exact — there is no floating-point rounding of the kind that affects large numbers in some calculators.

What do NAND, NOR, and XNOR do?

They are the bitwise negations of AND, OR, and XOR: NAND is NOT(A AND B), NOR is NOT(A OR B), and XNOR is NOT(A XOR B), each masked to the chosen width. NAND and NOR are universal gates from which any logic function can be built.