Skip to content
Math

Bitwise Calculator

Enter two integers, choose an operation, and get instant results in binary, decimal, octal and hexadecimal. The calculator covers all nine bitwise operations, including AND, OR, XOR, NOT, NAND, NOR, XNOR, left shift and right shift. Select your bit width (8, 16 or 32 bits) and input base, then see a step-by-step per-bit breakdown of exactly how each bit of the result was produced.

Your details

The bitwise operation to apply. NOT only uses A; shift operations treat B as the shift count.
The numeric base you want to type your inputs in.
Number of bits to use. Larger widths allow bigger values; results are masked to this width.
First operand. Enter a value in your chosen input base.
Second operand (not used by NOT). For shift operations this is the shift count.
Result (decimal)
12

Unsigned decimal result of the bitwise operation

Result (binary)00001100
Result (octal)14
Result (hexadecimal)C
A in binary00111100
B in binary00001101
Result12
A (binary len)-

& result: 12 decimal (0xC)

  • The 8-bit result has 2 set bits (1s) and 6 clear bits (0s).
  • AND is a masking operation: bits in the result are 1 only where both operands have 1.
  • Hex shorthand: 0xC, which is compact notation used in low-level code and color values.

Next stepCopy the binary, octal or hex result from the output cards. For multi-step logic you can chain results by pasting one result as the next operand.

Bit-by-bit breakdown (8-bit)

BitABOperationResult
7000 & 00
6000 & 00
5101 & 00
4101 & 00
3111 & 11
2111 & 11
1000 & 00
0010 & 10

Each row shows one bit position from the most significant (bit 7) to the least significant (bit 0).

What is a bitwise operation?

Bitwise operations work directly on the individual binary digits (bits) of an integer. Unlike ordinary arithmetic, which treats a number as a whole value, bitwise operations examine each bit position independently. Every modern CPU implements these operations natively in a single clock cycle, making them among the fastest operations available. They appear in graphics programming (color masking), network engineering (subnet masks), cryptography (stream ciphers), data compression, and any low-level code that needs to pack several flags into a single integer.

The nine operations this calculator supports

AND (&) returns 1 for a bit only when both A and B have a 1 there, so it is perfect for masking out bits. OR (|) returns 1 whenever either operand has a 1, so it combines or sets bits. XOR (^) returns 1 only when A and B differ at that position, making it ideal for toggling bits or detecting changes. NOT (~) flips every bit of a single operand. NAND is the complement of AND (NOT applied to the AND result), and NOR is the complement of OR. XNOR is the complement of XOR, returning 1 when both bits match. Left shift (<<) moves all bits toward the most significant end and fills vacated positions with zeros, multiplying the value by 2 for each shift. Logical right shift (>>>) moves bits toward the least significant end, filling vacated positions with zeros, which is unsigned integer division by 2 for each shift.

Bit widths: 8-bit, 16-bit and 32-bit

A bit width defines how many binary digits represent the number. An 8-bit (byte) value holds numbers from 0 to 255. A 16-bit (word) value spans 0 to 65,535. A 32-bit (doubleword) value spans 0 to 4,294,967,295. The bit width matters for NOT and shift operations because it determines how many bits get flipped or shifted. NOT applied to 0 gives 255 in 8-bit mode (11111111 binary), but 65,535 in 16-bit mode (1111111111111111 binary). Always choose the width that matches the data type in your programming language: uint8_t, uint16_t or uint32_t in C/C++, byte in Java, or the default integer size in your environment.

Reading results across number bases

This calculator shows the result in decimal, binary, octal and hexadecimal simultaneously. Binary is the native representation: each digit is a 0 or 1 mapping directly to one bit. Octal groups three bits into one digit, and hexadecimal groups four bits into one digit (0-9 then A-F), making it far more compact for inspecting bit patterns. A programmer using color values will often represent them as hex (e.g. 0xFF0000 for red), while a network engineer working with subnet masks prefers binary or decimal. Pick the base that suits your use case.

Bitwise operation truth table (single-bit)

ABANDORXORNANDNORXNOR
00000111
01011100
10011100
11110001

Shows the output for every combination of single-bit inputs A and B.

Frequently asked questions

What is the difference between AND and NAND?

NAND is simply NOT AND: it takes the AND result and inverts every bit. Where AND returns 1 only when both bits are 1, NAND returns 0 in that case and 1 everywhere else. NAND gates are the foundation of most digital logic circuits because any Boolean function can be built from NAND gates alone.

How is XOR useful in programming?

XOR is used for bit toggling (flipping specific bits without affecting others), swap tricks (swapping two integers without a temporary variable using three XOR operations), parity checks in error detection, and simple stream ciphers in cryptography. It is also the basis for RAID-5 parity calculations in storage systems.

Why does left shift multiply by two?

In binary, shifting all bits one position to the left is identical to multiplying by 2, just as moving digits one place left in decimal multiplies by 10. Shifting left by N places multiplies by 2^N, provided there is no overflow. This is why compilers often replace multiplication by powers of two with a shift instruction.

What does NOT do to negative numbers?

This calculator works with unsigned integers, so NOT simply flips all bits within the chosen bit width. In languages that use signed two's-complement integers (like C or Java), ~x equals -(x + 1). For example, ~5 = -6 in signed 32-bit arithmetic. To see the signed interpretation, note that if the result's most significant bit is 1, the value would be negative in a signed type.

What is the difference between logical and arithmetic right shift?

A logical right shift (the >>> operator) fills vacated high-order bits with zeros, treating the number as unsigned. An arithmetic right shift fills with the sign bit, preserving the sign for negative two's-complement numbers. This calculator performs logical right shift, consistent with unsigned integers.

How do I use this calculator for subnet masks?

Enter the IP address and subnet mask as 32-bit decimal values and choose AND as the operation. The result is the network address. For example, the host 192.168.1.100 AND the mask 255.255.255.0 gives 192.168.1.0, the network address. Convert each IP octet individually if you prefer, then combine them.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…