Interactive 32-bit Bitmask Calculator
Accepted formats: decimal (42), hex (0x2A), binary (0b101010).
Single-Bit Tools
What is a bitmask calculator?
A bitmask calculator helps you perform operations on individual bits inside a number. Instead of thinking about values only in decimal, you can directly manipulate binary flags. This is useful when you store many true/false settings in one integer, work with low-level APIs, optimize memory, or decode packed status fields.
In practical software development, bitmasks show up in networking, embedded systems, graphics, permissions, feature toggles, and game programming. A calculator like this one lets you quickly verify your logic before writing code.
Why bitmasks are so useful
- Compact storage: 32 yes/no values can fit in one 32-bit integer.
- Fast operations: bitwise instructions are very efficient on CPUs.
- Easy combinations: combine multiple flags with OR, test with AND.
- Predictable behavior: deterministic operations ideal for systems programming.
Core operations explained
AND (&)
Keeps bits that are 1 in both numbers. Use it to test if a flag is present.
if ((flags & READ_PERMISSION) !== 0) {
// user can read
}
OR (|)
Sets a bit to 1 if either side has 1. Use it to add a flag.
flags = flags | READ_PERMISSION;
XOR (^)
Flips bits where values differ. Useful for toggling a known flag.
flags = flags ^ DARK_MODE_ENABLED;
NOT (~)
Inverts all bits. Combined with AND, this is commonly used to clear bits:
flags = flags & ~READ_PERMISSION;
Shift operators (<<, >>>)
Shifts bit positions left or right. Left shift often builds masks quickly, while unsigned right shift is helpful when decoding packed fields.
Real-world examples
- User permissions: read/write/delete/admin as separate bits.
- Game states: poisoned, invisible, stunned, shielded flags.
- Network protocols: status bytes and control flags.
- Hardware registers: device configuration in embedded systems.
Common bitmask patterns
Set a bit
value = value | (1 << index)
Clear a bit
value = value & ~(1 << index)
Toggle a bit
value = value ^ (1 << index)
Check a bit
((value >> index) & 1) === 1
Important JavaScript note
JavaScript bitwise operators work on signed 32-bit integers internally. That means very large values are coerced into 32 bits. This calculator shows both signed interpretation and unsigned representation so you can debug behavior clearly.
Quick workflow for debugging
- Enter your current flag value as decimal, hex, or binary.
- Apply the operation you intend to use in code.
- Inspect decimal, hex, and binary outputs.
- Confirm specific bit positions with the Single-Bit Tools section.
If you regularly handle packed data or flag enums, a bitmask calculator saves time and prevents subtle bugs. Keep this page handy any time you need fast, reliable bitwise checks.