Bit Mask Calculator

Create and apply bit masks with visual toggles

Mask (Decimal)
0
Mask (Binary)
00000000
Mask (Hex)
0x00

AND (value & mask) — Masked result

Dec0
Bin00000000
Hex0x00

OR (value | mask) — Masked result (OR)

Dec0
Bin00000000
Hex0x00

XOR (value ^ mask) — Toggled bits

Dec0
Bin00000000
Hex0x00

Visual — Bits that survive the AND mask

Green = bit survives (1 in both value and mask) · Yellow = cleared by mask / no match

What is a Bit Mask?

A bit mask is a pattern of bits used with bitwise operators to isolate, set, or clear specific bits in a value. Each bit you select in the mask determines whether that position is affected when you apply it to your data.

AND Masking

Use AND masking to extract specific bits from a value. Bits in the result are 1 only where both the original value and the mask have 1s. It's how you read individual flags from a packed integer.

OR Masking

OR masking sets bits to 1 wherever the mask has a 1. Use it to enable specific flags in a value without modifying other bits — the classic pattern for setting configuration bits.

XOR Toggling

XOR toggles (flips) bits wherever the mask has a 1. Applying the same mask twice returns you to the original value, making XOR useful for simple encryption and hardware toggling.

Using This Calculator

I built this bit mask calculator because I was tired of mentally juggling hex values when working with hardware registers and permission flags. Click the bit toggles above to build your mask visually, enter a decimal value, and watch all three operations update in real time.

Real-World Use Cases

In embedded programming, a bit mask isolates individual bits from an ADC reading to extract sensor data. In C and Rust, file permission masks (like chmod) use bitwise OR to combine read, write, and execute flags. Graphics programmers use AND masks to extract color channel components from a packed pixel.

Bit Mask — Frequently Asked Questions

What is a bit mask?

A bit mask is a pattern of bits used to select, clear, or toggle specific bits in a binary value. By applying a mask with bitwise AND, OR, or XOR operations, you can extract or modify individual bits without affecting the rest of the value. This bit mask calculator lets you build masks visually and see the results instantly.

How do I create a bit mask?

To create a bit mask, decide which bit positions you want to include and set those bits to 1. For example, a mask for bits 0-3 (the lowest four bits) is 0000 1111 binary (0x0F hex, 15 decimal). You can use a bit mask calculator to visually toggle bits and see the resulting mask value in decimal, binary, and hex formats instantly.

What is the difference between AND, OR, and XOR masking?

AND masking (value & mask) clears all bits that are 0 in the mask — only bits that are 1 in both the value and the mask survive. OR masking (value | mask) sets all bits that are 1 in the mask to 1 in the result. XOR masking (value ^ mask) toggles all bits that are 1 in the mask. Use this bit mask calculator to experiment with all three operations simultaneously.

Why are bit masks useful in programming?

Bit masks allow you to pack multiple flags into a single integer, extract specific fields from hardware registers, apply permissions masks in file systems, and optimize storage by representing boolean states as individual bits rather than separate variables. Embedded developers, game programmers, and systems engineers use bit masks daily.

Bitwise Calculator →

AND, OR, XOR, NOT — online bitwise operations

Programmer (64-bit) →

64-bit base conversion with BigInt precision

SHA256 Hash Generator →

Compute SHA-256 checksums in your browser

Programming (32-bit) →

Multi-base number converter for developers

Bitwise Guide →

Complete reference for bitwise operators