Bitwise Calculator
Bitwise operations work on individual bits of integers. AND (&): bit is 1 only if both bits are 1. OR (|): bit is 1 if either bit is 1. XOR (^): bit is 1 if bits differ. NOT (~): flips all bits (two's complement for signed ints). Examples: 12 & 10 = 8 (1100 & 1010 = 1000), 12 | 10 = 14 (1100 | 1010 = 1110), 12 ^ 10 = 6 (1100 ^ 1010 = 0110), ~12 = -13. Left shift: 5 << 3 = 40 (multiply by 8).
Perform bitwise AND, OR, XOR, NOT, NAND, NOR, XNOR, and bit shift operations on integers. Shows result in decimal, binary (32-bit), hex, and octal. Visualizes bit-level operation side by side. Accepts decimal, hex (0xFF), and binary (0b1010) input.
Operation
Inputs
Accepts decimal (12), hexadecimal (0xFF), or binary (0b1010) input. Operates on 32-bit signed integers.
Presets
Bitwise Operations Reference
| A | B | AND | OR | XOR | NAND | NOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
Shift Operations
a << n— Left shift: multiply by 2^na >> n— Logical right shift: divide by 2^n (fills with 0)a >>> n— Arithmetic right shift: preserves sign bit
Common Use Cases
- Check bit set:
n & (1 << k) - Set bit:
n | (1 << k) - Clear bit:
n & ~(1 << k) - Toggle bit:
n ^ (1 << k) - Power of 2 check:
n & (n - 1) === 0
How to Use
- 1
Select an operation
Click the operation you want: AND, OR, XOR, NOT, NAND, NOR, XNOR, Left Shift, Right Shift, or Arithmetic Right Shift. NOT is unary (requires only value A).
- 2
Enter input values
Type values in decimal (12), hex (0xFF), or binary (0b1010). Both A and B fields are shown for binary operations; only A is needed for NOT.
- 3
View the result
See the result in decimal, hex, binary (32-bit grouped in nibbles), and octal. The bit-level visualization shows A and B aligned with the result.
- 4
Copy the result
Click Copy to get the result with decimal, binary, and hex representation. Use presets for quick common examples like bitmask operations.
Frequently Asked Questions
- What is a bitwise operation?
- A bitwise operation works directly on the binary representation of integers, processing each bit position independently. The main bitwise operators are AND (&): output bit is 1 only if both input bits are 1; OR (|): output is 1 if at least one input is 1; XOR (^): output is 1 if inputs differ; NOT (~): inverts all bits (0→1, 1→0). Example: 12 (1100) AND 10 (1010) = 8 (1000). All modern CPUs execute bitwise operations in a single clock cycle.
- What is the difference between AND, OR, and XOR?
- AND (&): both bits must be 1 to produce 1. Used for masking (extracting specific bits). Example: 0xFF & 0x0F = 0x0F (keeps only lower 4 bits). OR (|): either bit being 1 produces 1. Used for setting bits. Example: 0b1010 | 0b0101 = 0b1111. XOR (^): bits must differ to produce 1. Used for toggling bits or detecting differences. Example: 0xFF ^ 0x0F = 0xF0. XOR is also used for encryption and parity checking. XOR with itself always gives 0.
- What are bit shift operations?
- Bit shifts move all bits left or right by n positions. Left shift (<<): shift bits left, fill with 0s. Equivalent to multiplying by 2^n. Example: 5 << 3 = 40 (5 × 8). Right shift (>>): logical right shift fills with 0s; divides by 2^n. Arithmetic right shift (>>>) fills with the sign bit, preserving negative numbers. Example: -8 >>> 1 = 2147483644 (logical), -8 >> 1 = -4 (arithmetic). Shift by 0 returns the original value.
- What are NAND and NOR operations?
- NAND (NOT AND) outputs 0 only when both inputs are 1; otherwise outputs 1. It is the complement of AND. NOR (NOT OR) outputs 1 only when both inputs are 0; otherwise outputs 0. It is the complement of OR. Both NAND and NOR are "functionally complete" — any boolean function can be built using only NAND gates or only NOR gates. This makes them fundamental in digital circuit design. XNOR (NOT XOR) outputs 1 when inputs are equal.
- How do I check if a bit is set in a number?
- To check if bit k is set: use n & (1 << k). If the result is non-zero, the bit is set. Example: to check bit 3 of 12 (binary 1100): 12 & (1 << 3) = 12 & 8 = 8 ≠ 0, so bit 3 is set. To set bit k: n | (1 << k). To clear bit k: n & ~(1 << k). To toggle bit k: n ^ (1 << k). These patterns appear in flags, permission systems (like Unix chmod), and embedded programming.
- What is a bitmask?
- A bitmask is an integer used with bitwise AND, OR, or XOR to extract, set, or clear specific bits. To extract bits 4-7: value & 0xF0 = (value >> 4) & 0x0F. To check if multiple flags are set: (permissions & (READ | WRITE)) === (READ | WRITE). Bitmasks are used in: file permissions (Unix rwxrwxrwx), network subnet masks (255.255.255.0), graphics (RGBA color channels), and protocol flags. Example: IPv4 subnet mask 255.255.255.0 (binary: 11111111.11111111.11111111.00000000).