Logo

MonoCalc

/

Bit Mask Calculator

Encode/Decode

Quick Presets

Supports 0x (hex), 0b (binary), 0o (octal), or plain decimal
Auto-description: bits [15:8] are set (8 of 16 bits)

Interactive Bit Grid (click input/mask bits to toggle)

Input (set)

Mask (set)

Result (set)

 

12
8
4
0

Input

Mask

AND

Result

1
1
0
1
1
1
1
0
0
0
0
0
0
0
0
0

Result

Binary

1101111000000000

Hexadecimal

0xDE00

Decimal

56832

Octal

0o157000

Bit Statistics

Set Bits (popcount)

6

Zero Bits

10

MSB Position

15

LSB Position

9

Mask description: bits [15:8] are set (8 of 16 bits)

Bit-Field Extraction (optional)

Extract a contiguous range of bits from the result. Leave blank to skip.

About This Tool

🎭 Bit Mask Calculator – Apply, Visualize, and Analyze Bitmasks

The Bit Mask Calculator is an interactive bitwise tool designed for developers, embedded-systems engineers, students, and security researchers. It lets you apply any bitwise operation — AND, OR, XOR, NOT, NAND, NOR, Left Shift, Right Shift — to integer values and instantly see the result in binary, hexadecimal, decimal, and octal. A live, color-coded bit grid shows exactly which bits are set, cleared, or changed, making abstract bit operations visual and intuitive.

What Is Bit Masking?

A bitmask is an integer used as a template to selectively read, set, clear, or toggle individual bits in another integer. By combining a value with a mask using a bitwise operator, you gain precise, efficient control over individual bit positions without affecting others. This technique is a cornerstone of:

  • Embedded systems — controlling CPU/MCU register flags (e.g., enabling a UART interrupt by ORing a control register with a mask)
  • Unix permissionschmod 755 corresponds to mask 0x1ED; ANDing with 0x7 extracts owner permissions
  • Network protocols — parsing IPv4 headers, extracting subnet masks, isolating TCP flag fields
  • Color manipulation — extracting RGBA channels from a packed 32-bit color value like 0xFF5733FF
  • Cryptography & hashing — XOR-based key mixing, parity checks, and Hamming weight analysis

Supported Bitwise Operations

OperationSymbolRuleCommon Use
AND&Output 1 only when both bits are 1Isolate / mask bits
OR|Output 1 when either bit is 1Set / enable flags
XOR^Output 1 when bits differToggle bits, parity, encryption
NOT~Flip every bit (within bit width)One's complement, clear all
NAND~(&)Complement of ANDLogic gate emulation
NOR~(|)Complement of ORLogic gate emulation
Left Shift<<Shift bits left, fill with 0Multiply by 2ⁿ, build masks
Right Shift>>Shift bits right, fill with 0Divide by 2ⁿ, extract upper bits

The Three Core Masking Patterns

1. Read / Isolate Bits (AND)

AND your value with a mask that has 1s only in the positions you want to read. All other bits become 0.

Value = 0b11011010  (0xDA)
Mask  = 0b00001111  (0x0F)  ← lower nibble
AND   = 0b00001010  (0x0A)  ← only lower 4 bits remain

2. Set / Enable Bits (OR)

OR your value with a mask that has 1s in the positions you want to force to 1. All other bits are unchanged.

Value = 0b10100000  (0xA0)
Mask  = 0b00000101  (0x05)  ← bits 0 and 2
OR    = 0b10100101  (0xA5)  ← bits 0 and 2 are now set

3. Clear / Disable Bits (AND with inverted mask)

AND your value with the bitwise NOT of your mask. This clears only the bits covered by the mask without touching others.

Value  = 0b11111111  (0xFF)
~Mask  = 0b11110000  (0xF0)  ← NOT of 0x0F
AND    = 0b11110000  (0xF0)  ← lower 4 bits cleared

Bit-Field Extraction

The bit-field extraction feature lets you isolate a contiguous range of bits from the result. Specify the High (MSB) and Low (LSB) bit positions, and the calculator automatically builds the appropriate mask, applies it, and right-shifts to give you the field value. This is essential when parsing packed structs, protocol headers, or RGBA color channels.

For example, to extract bits [23:16] from 0xABCD1234: the calculator masks with 0x00FF0000 and shifts right by 16 to yield 0xCD (decimal 205).

Color-Coded Bit Grid

The interactive bit grid displays three rows simultaneously:

  • Blue — Input value bits (clickable to toggle)
  • Orange — Mask value bits (clickable to toggle)
  • Green — Result bits after the operation

When a bit-field range is specified, the relevant columns are highlighted with a purple border. Bits are grouped in blocks of 8 (one byte per group) with bit-index labels for easy reading.

Input Format Support

The calculator accepts values in all standard integer notations. Prefix auto-detection works regardless of the currently selected base:

  • 0x or 0X — Hexadecimal (e.g., 0xFF00)
  • 0b or 0B — Binary (e.g., 0b11011010)
  • 0o or 0O — Octal (e.g., 0o377)
  • No prefix — Decimal (e.g., 255)

BigInt Precision for 64-Bit Values

All arithmetic is performed using JavaScript's native BigInt type, which avoids the 32-bit signed ceiling imposed by standard JS bitwise operators (which convert operands to 32-bit integers internally). This means the calculator handles 64-bit unsigned values up to 2⁶⁴ − 1 (18,446,744,073,709,551,615) without overflow or loss of precision.

Frequently Asked Questions

Is the Bit Mask Calculator free?

Yes, Bit Mask Calculator is totally free :)

Can I use the Bit Mask Calculator offline?

Yes, you can install the webapp as PWA.

Is it safe to use Bit Mask Calculator?

Yes, any data related to Bit Mask Calculator only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does the Bit Mask Calculator work?

Enter an input value and a mask value in binary, octal, decimal, or hexadecimal notation, then choose a bitwise operation (AND, OR, XOR, NOT, NAND, NOR, SHIFT). The tool applies the mask, displays the result in all four bases, and renders a color-coded bit grid showing exactly which bits are set, cleared, or changed.

What is bit masking and why is it useful?

Bit masking uses bitwise operations to selectively read, set, clear, or toggle individual bits in an integer. It is widely used in embedded systems for register control, file permission checks (Unix chmod), network protocol parsing, color channel extraction, and cryptographic operations.

How do I extract a specific bit field from a value?

Use the Bit Field Extraction section: enter the High (MSB) and Low (LSB) bit positions of the field you want. The calculator shifts and masks the input to isolate exactly those bits, displaying the extracted field value alongside the highlighted region in the bit grid.

What is the difference between NAND and NOR operations?

NAND is the complement of AND — it produces 1 unless both input and mask bits are 1. NOR is the complement of OR — it produces 1 only when both bits are 0. Both are bitwise complements of their parent operations constrained to the selected bit width.

Can this calculator handle 64-bit values?

Yes. All arithmetic uses JavaScript's BigInt, which avoids the 32-bit signed ceiling of standard JS operators. Values up to 2⁶⁴ − 1 are fully supported across all operations and bit widths (8, 16, 32, 64).

What are common mask presets and when should I use them?

Common presets include 0xFF (lower byte), 0xFF00 (second byte), 0xF0F0F0F0 (alternating nibbles), chmod 755 (0x1ED), and IP subnet /24 (0xFFFFFF00). Use presets to quickly explore standard masking patterns without manually entering hex values.