FormatterHQ

Bitwise Calculator

Run AND, OR, XOR, NAND, NOR, XNOR, NOT, left shift and right shift on whole numbers in any common base, with fixed bit widths and a full breakdown.

Loading tool…
Ready.

How to use the Bitwise Calculator

  1. Type your numbers in Operand A and Operand B. For shifts, the second field holds the shift amount; NOT uses Operand A only.
  2. Choose the operation, the base of each operand and the bit width.
  3. Read the result in unsigned and signed decimal, hex, octal and binary.
  4. Copy the value, or switch the operation to compare results.

An all-in-one bitwise calculator

This bitwise calculator applies logic operations to integers one bit at a time. Choose AND, OR, XOR, NAND, NOR, XNOR, NOT, shift left or shift right, pick a bit width, and get the answer in several bases, with the operands aligned in binary so you can follow every bit.

Operations at a glance

OperationResult bit is 1 when…In C-style code
ANDall inputs are 1a & b
ORany input is 1a | b
XORthe inputs differa ^ b
NANDnot all inputs are 1~(a & b)
NORall inputs are 0~(a | b)
XNORthe inputs are equal~(a ^ b)
NOTthe input is 0~a

Example with hex masks

The two values 0xF0F0 and 0x0FF0 give a good feel for the three basic operations:

0xF0F0 AND 0x0FF0 = 0x00F0   (240)
0xF0F0 OR  0x0FF0 = 0xFFF0   (65520)
0xF0F0 XOR 0x0FF0 = 0xFF00   (65280)

AND keeps the overlap, OR merges both, and XOR keeps only the bits that are in one value but not the other.

Bit shifts

For shifts, Operand A is the value and the second field, relabelled "Shift by (bits)", is how many positions to move it.

  • Shift left (<<) moves bits toward the high end and fills with zeros. Each step multiplies by 2 while nothing overflows: 5 << 2 = 20. Bits pushed past the chosen width are dropped, so 0xF0F0 << 4 is 0xF0F00 in 32-bit mode but 0x0F00 in 16-bit mode.
  • Shift right (>>) moves bits toward the low end, discarding the lowest ones, which divides by 2 per step and rounds down: 100 >> 3 = 12, and 0xF0F0 >> 4 = 0x0F0F.

Right shifts here are logical: zeros always come in from the top. In 8 bits, -1 is stored as 255, and 255 >> 1 gives 127. An arithmetic shift, like Java's or C#'s >> on a signed int, would copy the sign bit and keep −1 instead. JavaScript's >>> is the logical form.

Bit width and signed results

Every input is reduced to the chosen width (8, 16, 32 or 64 bits), and negative numbers are stored in two's complement. When the result's top bit is set, a signed line is added: 1 << 7 in 8 bits is 128 unsigned, but −128 signed.

Input details

  • Each operand has its own input base for plain values; a 0x, 0b or 0o prefix overrides it for that value.
  • AND, OR, XOR and their inverted forms take two operands; NOT inverts Operand A alone. For a longer chain, type the result back into Operand A.
  • Only whole numbers are allowed; a fraction produces an error.

A precedence trap in code

In C, C++ and JavaScript, equality comparison binds more tightly than the bitwise operators, so x & 1 == 0 means x & (1 == 0). Always write (x & 1) == 0. Checking the expected value here first makes such bugs easier to spot.

Single-operation pages such as the AND calculator and XOR calculator explain each operation in more depth. To convert a result into another base, use the all number converter.

Frequently asked questions

What does a left shift do to a number?
Shifting left by n multiplies the value by 2^n, as long as no set bits fall off the top of the chosen width. For example, 5
Is the right shift arithmetic or logical?
It is logical: zeros are shifted in from the left, and the value is treated as unsigned. That matches JavaScript's >>> operator and unsigned types in C, not the sign-preserving >> used on signed integers.
Which bit width should I choose?
Use the width of the variable or register you are modeling: 8 for a byte, 16 for a short, 32 for an int, 64 for a long. The width decides where results overflow and how NOT, NAND, NOR and XNOR fill the high bits.
Can I enter hexadecimal and binary numbers?
Yes. Set the input base, or prefix individual values with 0x for hex, 0b for binary or 0o for octal. You can mix prefixed values in a single calculation.
Why does the calculator show a negative signed value?
When the highest bit of the result is 1, the same pattern means a negative number in two's complement. The tool shows the unsigned value first and adds the signed reading so you can use whichever your code expects.

Last updated October 3, 2026

Guides

Related tools