GALAXY OF TOOLS

SCIENCE SECTOR

Bitwise Calculator

AND, OR, XOR, NOT, shifts and rotates on 8–64-bit values in dec, hex, binary or octal, with clickable bits.

Width
Interpretation
Input base

Prefixes 0x, 0b and 0o override the input base; a leading minus is accepted in decimal. Shift and rotate counts are read as plain decimal.

HexDecimalBinaryOctal
Bit fields — click a bit of A or B to toggle it
Mask builder

Runs entirely in your browser. Nothing you enter or upload is sent to a server.

Bitwise calculator for AND, OR, XOR, shifts and rotates

This bitwise calculator performs the operations that programmers, electronics engineers and students meet every day — AND, OR, XOR, NOT, NAND, NOR, XNOR, logical and arithmetic shifts, rotates and two’s-complement negation — on values of 8, 16, 32 or 64 bits. Type the operands in decimal, hexadecimal, binary or octal, choose whether the bits are read as unsigned or signed, and the result is shown in every base at once, together with a bit-by-bit view in which you can click any bit of A or B to flip it.

Unlike a general-purpose calculator, it respects the word width: a 32-bit shift left discards bits that fall off the end, an arithmetic shift right copies the sign bit, rotates wrap the bits around, and the signed and unsigned readings of the same pattern are both printed. Arithmetic is done with 64-bit-safe big integers, so there are no rounding surprises beyond 2⁵³. A mask builder produces the constant for a bit range and shows how to extract, set, clear or toggle that field.

How to use the Bitwise Calculator

  1. Pick the Width (8, 16, 32 or 64 bits), the Interpretation (unsigned or signed two’s complement) and the Input base. Prefixes 0x, 0b and 0o always override the base.
  2. Enter Operand A, choose the Operation and enter Operand B (or the shift/rotate count). Unary operations disable B.
  3. Read the result as hex in the result box and in hex, decimal (unsigned and signed), binary and octal in the table, which also lists NOT A and −A.
  4. Click bits in the Bit fields rows to toggle individual bits of A or B; the inputs and the result update immediately.
  5. Open the Mask builder to get a mask for a bit range and see A AND/OR/XOR mask and the extracted field value.
  6. Use the copy buttons for the hex result, the binary string or the whole table.

Bitwise Calculator features

Width-exact arithmetic

Every result is reduced to the chosen width, exactly as a CPU register would hold it, with a note when input values wrap or shifted bits overflow.

Signed and unsigned views

The decimal column prints both readings whenever the sign bit is set, so 0xFFFFFFFF shows 4294967295 and −1 side by side.

All shift flavours

Logical shift right (>>>) fills with zeros, arithmetic shift right (>>) copies the sign bit, and ROL/ROR rotate within the word — matching Java, C#, JavaScript and assembly semantics.

Clickable bit fields

Bits are numbered from the MSB down to bit 0 in groups of eight; clicking one flips it in the operand and recomputes everything.

Mask builder

Enter a low and high bit to get the mask in hex, binary and decimal, optionally inverted, plus extract/set/clear/toggle results for operand A.

Bitwise operations at a glance

OperationSymbol (C/JS)Rule per bitExample (8-bit)
AND&1 only if both bits are 10xF0 & 0x3C = 0x30
OR|1 if either bit is 10xF0 | 0x3C = 0xFC
XOR^1 if the bits differ0xF0 ^ 0x3C = 0xCC
NOT~flips every bit~0xF0 = 0x0F
Shift left<<moves bits up, fills with 0 (×2 per step)0x0F << 2 = 0x3C
Logical shift right>>>moves bits down, fills with 00xF0 >>> 4 = 0x0F
Arithmetic shift right>>moves bits down, fills with the sign bit0xF0 >> 4 = 0xFF (signed −16 → −1)
Rotate left / rightROL / RORbits that fall off re-enter at the other end0x81 ROL 1 = 0x03

Two’s complement and signed values

In two’s complement the top bit carries weight −2w−1 instead of +2w−1. An 8-bit pattern 1111 1111 is therefore 255 when read as unsigned and −1 when read as signed; the bits are identical and only the interpretation changes. Negating a number means inverting every bit and adding one, which is what the −A row shows. The one special case is the most negative value (−128 in 8 bits, −2³¹ in 32 bits): its negation does not fit and wraps back to itself, which the calculator flags.

Arithmetic shift right divides a signed value by two per step, rounding toward negative infinity, while a logical shift divides the unsigned reading. Java and JavaScript expose both (>> and >>>); C and C++ leave right-shifting a negative value implementation-defined, which is why the two options are listed separately here.

Masks: testing, setting and clearing bits

  • Test bit n: (x & (1 << n)) != 0.
  • Set bits: x | mask; clear bits: x & ~mask; toggle bits: x ^ mask.
  • Extract a field in bits lo…hi: (x & mask) >> lo, where the mask is ((1 << (hi − lo + 1)) − 1) << lo — the mask builder prints exactly this constant.
  • Hardware registers, network headers, Unix file permissions and colour values (0xRRGGBB) are all bit fields; the chmod calculator and number base converter cover two of the most common cases, and the truth table generator shows the single-bit logic behind each operator.

Bitwise Calculator FAQ

How do I calculate 0xF0 AND 0x3C with the bitwise calculator?

Leave the input base on Hex, type F0 as operand A, choose A AND B and type 3C as operand B. The result is 0x30: only bits 4 and 5 are set in both values.

What is the difference between >> and >>>?

>> is the arithmetic shift, which keeps the sign by filling with copies of the top bit; >>> is the logical shift, which fills with zeros. They differ only when the sign bit is 1.

Why does my 32-bit shift produce 0?

Shifting by the full width or more pushes every bit out, so the result is 0 (or all ones for an arithmetic shift of a negative number). Some CPUs mask the count instead; the calculator follows the mathematical definition.

Can I enter negative numbers?

Yes, in Signed mode and decimal input, for example −5. It is stored as the two’s-complement pattern for the chosen width (0xFB for 8 bits). In Unsigned mode a negative input is rejected.

Does it handle 64-bit values exactly?

Yes. Values are processed as big integers, so 0xFFFFFFFFFFFFFFFF and shifts such as 1 << 63 are exact, unlike calculators that use floating point.

How do I get a bit mask for bits 4 to 7?

Open the Mask builder, enter 4 as the low bit and 7 as the high bit. The mask is 0xF0 (binary 1111 0000, decimal 240); the inverted option gives the complement for clearing those bits.

You might also need