Bitwise Calculator
AND, OR, XOR, NOT, NAND, NOR, XNOR on decimal, hex or binary operands.
Apply AND, OR, XOR, NOT or a bit shift to integer operands.
Inputs
- A
- B
- Operation
What it does
Applies AND, OR, XOR, NOT, NAND, NOR and XNOR bit by bit to two numbers written in decimal, hex or binary.
Where it's used
Setting, clearing and testing register bits in firmware, masks and flags.
How to use it
- Type operand A (decimal,
0xhex or0bbinary). - Choose the operation.
- Type operand B (not needed for NOT).
- Choose the word size.
The formula explained
- Set bit n
- x | (1 ≪ n)
- Clear bit n
- x & ~(1 ≪ n)
- Toggle bit n
- x ^ (1 ≪ n)
- Test bit n
- (x ≫ n) & 1
Worked example
Inverting the bits of 0x3C by XOR with 0xFF.
Inputs:
- Operand A: 0x3C
- Operation: XOR
- Operand B: 0xFF
- Word size: 8-bit
The calculator gives:
- Decimal (unsigned): 195
- Decimal (signed): -61
- Hexadecimal: 0xC3
Tips and common mistakes
- AND with a mask keeps bits, OR sets bits, XOR flips bits.
- NOT depends on the word size: ~0 is 0xFF in 8 bits but 0xFFFF in 16.
- Hex makes masks easy to read: each digit is 4 bits.
Questions people ask
How do I set, clear, toggle or test one bit?
Set: x |= 1 << n. Clear: x &= ~(1 << n). Toggle: x ^= 1 << n. Test: (x >> n) & 1. These are the everyday tools for microcontroller registers.
Why does 0xC3 show as both 195 and −61?
Unsigned, 0xC3 is 195. As a signed 8-bit number the top bit means −128, so it is 195 − 256 = −61. The bits are the same; only the interpretation changes.
How do I pull a field out of a register?
Shift it down, then mask it: (x >> shift) & mask. The upper four bits of 0xC3 are (0xC3 >> 4) & 0xF = 0xC.
Related Digital Logic calculators
- Binary Calculator
- Number System Converter
- Logic Gate Calculator
- Two's Complement Calculator
- Parity Bit Calculator
- Hamming Code Calculator
- Truth Table Generator
- Karnaugh Map Solver
- Gray Code Converter
- Bit Shift Calculator
Enter your values to get the result with the formula, substituted values and an explanation of each step.