Bitwise Calculator

Perform AND, OR, XOR, NOT, shift operations. Enter decimal, hex, or binary. Click bits to toggle them.

Decimal
Hexadecimal
Binary

Input A — click bits to toggle

Input B — click bits to toggle

Result bits

Enter values above or click bits to calculate.

How to Use the Bitwise Calculator

  1. Select bit width — choose 8-bit, 16-bit, or 32-bit mode at the top.
  2. Enter your values — type in decimal (e.g., 42), hexadecimal (0x2A), or binary (0b101010).
  3. Choose an operation — AND, OR, XOR, NOT, Left Shift, or Right Shift.
  4. See results instantly — results appear in decimal, hex, and binary simultaneously.
  5. Toggle bits visually — click any bit in the input grids to flip it and see how the result changes.

Understanding Bitwise Operations

Bitwise operations are one of the most fundamental tools in a programmer's toolkit. Unlike arithmetic operators that work on the full numeric value, bitwise operators work directly on the individual binary digits (bits) that make up a number. This gives programmers fine-grained control over memory, flags, masks, and data encoding — all with extremely fast CPU-level instructions.

AND (&) — Masking and Testing Bits

The AND operation returns a 1 only when both corresponding bits are 1. Its most common use is bit masking: extracting specific bits from a value by ANDing with a mask. For example, 0xFF & value extracts the lowest 8 bits of any integer. In network programming, AND is used to extract the network portion of an IP address from a subnet mask.

OR (|) — Setting Bits

OR returns a 1 when at least one bit is 1. It is the standard way to set specific bits without changing the others. For example, in a Unix permissions system, permissions | 0x4 sets the read bit. In graphics, OR combines color channel values. In flag-based configuration, OR merges multiple options into a single integer.

XOR (^) — Toggling and Simple Encryption

XOR returns 1 only when exactly one of the two bits is 1. XOR has a special property: a ^ b ^ b == a, which means XORing a value twice with the same key returns the original. This makes XOR perfect for toggling bits and for simple cipher algorithms. It is also used in RAID parity, CRC checksums, and swap-without-temp-variable tricks in C.

NOT (~) — Bitwise Complement

NOT flips every bit in the number. In an 8-bit system, NOT 0 becomes 255 (0b11111111). In standard 32-bit signed integers, NOT n equals -(n+1), so NOT 42 is -43. This is because of two's complement representation used by virtually all modern CPUs. NOT is used to create inverse masks for clearing bits, and in checksum algorithms.

Left Shift (<<) and Right Shift (>>)

Shift operations move all bits left or right by a specified number of positions. Left shift by n is equivalent to multiplying by 2^n (fast multiplication). Right shift by n is equivalent to integer dividing by 2^n (fast division). These operations are heavily optimized in CPU hardware and appear in virtually every high-performance algorithm, from image processing to network packet parsing to hash functions.

Practical Applications

Bitwise operations are used daily in: network programming (subnet masking, port flags), game development (collision detection flags, tile maps), embedded systems (hardware register manipulation), cryptography (cipher primitives, hash functions), compression algorithms (Huffman coding, LZ77), permission systems (Unix chmod), and compiler optimization (replacing multiply/divide with shifts).

Number Bases: Decimal, Hex, Binary

This tool accepts input in all three common bases. Decimal (base 10) is the normal everyday number system. Hexadecimal (base 16) uses digits 0–9 and letters A–F. One hex digit represents exactly 4 bits, so 0xFF is 8 bits and 0xFFFF is 16 bits — perfect for byte-level thinking. Binary (base 2) shows the exact bit pattern. Prefix hex with 0x and binary with 0b to specify the base explicitly. The tool also accepts plain decimal integers.

Frequently Asked Questions

A bitwise operation works directly on the individual bits (0s and 1s) of an integer. Common bitwise operations include AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). They are used extensively in low-level programming, networking, encryption, and graphics.
AND returns 1 only when both bits are 1. OR returns 1 when at least one bit is 1. XOR (exclusive OR) returns 1 only when exactly one of the two bits is 1. XOR is commonly used for toggling bits and simple encryption.
The NOT (bitwise complement) operation flips every bit in the number. In 8-bit mode, NOT 5 (00000101) becomes 250 (11111010). In signed 32-bit integers, NOT is equivalent to -(n+1). The result depends on the bit-width mode selected.
A left shift (<<) moves all bits to the left by a specified number of positions, effectively multiplying by 2 for each shift. A right shift (>>) moves bits to the right, dividing by 2 for each position. Bits shifted out of range are discarded.
Different contexts require different number representations. Decimal is the everyday format. Hexadecimal is compact and common in memory addresses and color codes. Binary shows the exact bit pattern, which is essential for understanding what a bitwise operation actually does.