Bitwise Calculator - AND, OR, XOR, NOT, Shift Operations
Perform bitwise logic operations on integers instantly with decimal, binary, and hex input/output.
Select an operation and enter values in decimal, binary, or hexadecimal to compute bitwise results.
Bitwise Calculator - AND, OR, XOR, NOT, Shift Operations
Perform bitwise logic operations on integers instantly with decimal, binary, and hex input/output.
About the Bitwise Calculator
Bitwise operations are fundamental computational operations that work directly on the binary representation of integers. Rather than treating a number as a whole value, bitwise operators examine and manipulate each individual bit position independently. This low-level control makes them invaluable in systems programming, embedded development, cryptography, and performance-critical algorithms.
The AND operation (&) produces a 1 in each bit position where both operands have a 1. It is commonly used to mask specific bits — for example, `value & 0xFF` extracts only the lowest 8 bits of any integer. The OR operation (|) sets a bit if either or both operands have that bit set, making it useful for combining flags and setting specific bits. The XOR operation (^) outputs 1 only when the two input bits differ, making it ideal for toggling bits, checking equality, and certain encryption algorithms.
The NOT operation (~) inverts every bit in the operand. In JavaScript's 32-bit signed integer model, `~n` is equivalent to `-(n + 1)`. The result is displayed as an unsigned 32-bit binary string for clarity. Left shift (<<) moves all bits to the left by the specified number of positions, which is equivalent to multiplying by powers of 2. Right shift (>>>) moves bits to the right, equivalent to integer division by powers of 2.
Bitwise operations execute in a single CPU clock cycle on modern hardware, making them significantly faster than equivalent arithmetic operations. This efficiency is why they appear frequently in hash functions, checksum algorithms, color packing in graphics (storing RGBA channels in a single 32-bit integer), permission flags in operating systems, and network protocol implementations.
This calculator accepts inputs in decimal (base 10), binary (base 2), or hexadecimal (base 16) and returns results in all three formats simultaneously, so you can cross-reference representations without manual conversion. All calculations use JavaScript's 32-bit integer bitwise semantics consistent with the ECMAScript specification.
Bitwise Operation Examples
Common bitwise operation examples showing input values and results in decimal and binary.
| Operation | Result (Decimal) | Binary Representation |
|---|---|---|
| 12 AND 10 | 8 | 1100 & 1010 = 1000 |
| 12 OR 10 | 14 | 1100 | 1010 = 1110 |
| 12 XOR 10 | 6 | 1100 ^ 1010 = 0110 |
| NOT 5 | -6 | ~00000101 = 11111010 (signed 32-bit) |
| 3 LEFT SHIFT 2 | 12 | 011 << 2 = 1100 (multiply by 4) |
| 24 RIGHT SHIFT 3 | 3 | 11000 >>> 3 = 00011 (divide by 8) |
How to Use the Bitwise Calculator
- Select the bitwise operation you want to perform: AND, OR, XOR, NOT, Left Shift, or Right Shift.
- Choose the input format — Decimal, Binary, or Hex — that matches your numbers.
- Enter the first number in the First Number field using the selected format.
- For binary operations (AND, OR, XOR, shifts), enter the second number or shift amount in the Second Number / Shift Amount field.
- Click Calculate to see the result displayed in decimal, binary, and hexadecimal simultaneously.
Bitwise Calculator FAQ
What is a bitwise AND operation?
A bitwise AND compares each pair of corresponding bits from two numbers and outputs 1 only if both bits are 1, otherwise 0. For example, 12 AND 10 in binary is 1100 & 1010 = 1000, which equals 8 in decimal. It is commonly used to mask or extract specific bits.
How does bitwise XOR work?
Bitwise XOR (exclusive OR) outputs 1 when the two input bits differ, and 0 when they are the same. For example, 12 XOR 10 is 1100 ^ 1010 = 0110 = 6. XOR is widely used in encryption, checksums, and toggling specific bits without affecting others.
What does the NOT operation do to a number?
The bitwise NOT (~) inverts all bits of the operand. In 32-bit signed integer arithmetic, ~n equals -(n + 1). So ~5 = -6, and ~0 = -1. The result is shown as an unsigned 32-bit binary string in this calculator to display all flipped bits clearly.
How are left and right shifts different?
Left shift (<<) moves all bits toward the most significant position by the specified count, filling vacated positions with zeros. This is equivalent to multiplying by 2 raised to the shift amount. Right shift (>>>) moves bits toward the least significant position, filling with zeros, equivalent to integer division by powers of 2.
When should I use hexadecimal input?
Hexadecimal is convenient when working with memory addresses, color codes (e.g., 0xFF0000 for red), network masks, or any value typically expressed as hex in documentation or source code. Each hex digit represents exactly 4 bits, making hex a compact human-readable representation of binary data.
Why do bitwise operations matter in programming?
Bitwise operations execute in a single CPU cycle, making them extremely fast. They are essential in systems programming for setting hardware registers, in graphics for packing RGBA colors, in cryptography for encryption algorithms, and in game development for compact flag storage. Understanding them is fundamental to computer science.