🎭 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 permissions —
chmod 755corresponds to mask0x1ED; ANDing with0x7extracts 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
| Operation | Symbol | Rule | Common Use |
|---|---|---|---|
| AND | & | Output 1 only when both bits are 1 | Isolate / mask bits |
| OR | | | Output 1 when either bit is 1 | Set / enable flags |
| XOR | ^ | Output 1 when bits differ | Toggle bits, parity, encryption |
| NOT | ~ | Flip every bit (within bit width) | One's complement, clear all |
| NAND | ~(&) | Complement of AND | Logic gate emulation |
| NOR | ~(|) | Complement of OR | Logic gate emulation |
| Left Shift | << | Shift bits left, fill with 0 | Multiply by 2ⁿ, build masks |
| Right Shift | >> | Shift bits right, fill with 0 | Divide 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:
0xor0X— Hexadecimal (e.g.,0xFF00)0bor0B— Binary (e.g.,0b11011010)0oor0O— 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.