Apply AND, OR, XOR and AND-NOT between a value and a mask, bit by bit – the four operations behind testing, setting, toggling and clearing flags.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
Four operations, all of flag-craft
Every flags field ever manipulated used these four idioms: AND to test or isolate, OR to set, XOR to toggle, AND-NOT to clear. This calculator aligns value, mask and result bit-for-bit so each column’s logic is inspectable — the truth tables enacted on your data.
Choose the width, feed value and mask in binary, decimal or hex, and chain results into follow-up operations to model read-modify-write sequences.
Worked example
value 10110101, mask 00001111 (8-bit) AND 0000 0101 — low nibble isolated OR 1011 1111 — low bits forced on XOR 1011 1010 — low bits flipped AND NOT 1011 0000 — low bits cleared
| Idiom | Operation | Use |
|---|---|---|
| test | value AND mask | is a flag set? |
| set | value OR mask | switch flags on |
| toggle | value XOR mask | flip flags |
| clear | value AND NOT mask | switch flags off |
Reading masks like prose
0x0F is “low nibble”, 0xF0 “high nibble”, 0x80 “top bit”, (1<<n) “bit n alone”. Fluency is recognising the shape at sight — and the aligned display trains exactly that recognition, one operation at a time.
Subnetting is masking
An IPv4 netmask ANDs against an address to keep the network part: 255.255.255.0 clears the host octet. Same operation, bigger field — the octet-by-octet view here transfers directly.
Privacy
Value and mask combine in your browser; neither is uploaded or logged.
How to use the Binary Bitmask Calculator
- Enter the value in the first panel and the mask in the second (binary, decimal or hex input).
- Choose AND, OR, XOR or AND-NOT and the bit width.
- Click "Apply mask".
- Value, mask and result are aligned bit-for-bit so each column's logic is visible.
Frequently asked questions
What are the four mask idioms?
AND tests/isolates (keep only masked bits), OR sets (force masked bits on), XOR toggles (flip masked bits), AND-NOT clears (force masked bits off). Every flags register, permission field and hardware register is manipulated with exactly these four.
How do I check whether bit 3 is set?
AND with the mask 00001000 (bit 3 only): a non-zero result means set. The aligned display shows the single surviving column – the visual version of (value & (1<<3)) != 0.
Why AND-NOT rather than subtraction to clear bits?
Subtraction borrows across columns when the bit is not set, corrupting neighbours; AND-NOT clears the target unconditionally and touches nothing else. value & ~mask is the only safe clear.
What does XOR toggling enable?
State flipping without reading first – toggle an LED bit, swap variables without a temp, build parity. XOR twice with the same mask restores the original, which the calculator demonstrates in two clicks.
How do masks relate to subnetting?
An IP netmask ANDs with an address to extract the network part – 255.255.255.0 is eight 1-bits low-cleared. The same aligned-columns reading applies, octet by octet.
Can I chain operations?
Yes – copy a result into the value panel and apply the next mask. Set-then-clear sequences model read-modify-write register updates faithfully.
Is everything processed locally?
Yes – value and mask are combined in-page; nothing is uploaded or recorded.