🔧 Mode
📐 Width & signedness
⚙️ Operation
🔁 Convert
📤 Result
🧱 All bases
ℹ️ About Bitwise Calculator
What is a bitwise operation?
A bitwise operation works on the individual binary digits (bits) of an integer rather than on the integer's numeric value. Each operation lines two values up bit-for-bit and emits a third value built by applying the rule (AND, OR, XOR, …) to each pair of bits. Bitwise math is the bedrock of low-level systems programming, compression, hashing, graphics, networking, and cryptography.
This calculator supports the six standard logical operators (AND, OR, XOR, NOT, NAND, NOR) and three shift operators (left shift, arithmetic right shift, unsigned right shift) on 32-bit and 64-bit integers under both signed (two's complement) and unsigned interpretations. Every result is rendered simultaneously in binary, octal, decimal, and hexadecimal.
The operators in detail
- AND (
a & b) — bit is 1 only when both inputs are 1. Used to mask off ranges of bits. - OR (
a | b) — bit is 1 when either input is 1. Used to set flags. - XOR (
a ^ b) — bit is 1 when exactly one input is 1. Foundation of one-time pads, checksums, and toggling flags. - NOT (
~a) — flips every bit. On unsigned widths this is the bit complement; on signed widths it equals-a − 1. - NAND —
NOT (a AND b). Universal gate in digital logic. - NOR —
NOT (a OR b). The other universal gate. - SHL (
a << b) — left shift; equivalent to multiplying by 2b when the result fits the width. - SHR (
a >> b) — arithmetic right shift; preserves the sign bit on signed widths. Equivalent to integer division by 2b. - USHR (
a >>> b) — unsigned (logical) right shift; always pads in zeros, ignoring the sign bit.
Signed vs unsigned, 32 vs 64
Modern CPUs and most programming languages support both signed and
unsigned integers. In two's complement encoding the high (sign) bit indicates a
negative value: for a 32-bit signed integer the range is -2,147,483,648 … 2,147,483,647,
while the unsigned range is 0 … 4,294,967,295 (0xFFFFFFFF).
64-bit math doubles the width — and exceeds JavaScript's safe-integer range of 253 − 1. This calculator uses BigInt for 64-bit work so the math is exact for all 64-bit values.
Toggle signed to change how negative inputs are accepted and how the decimal output interprets the high bit. The binary, octal, and hex outputs always show the raw bit pattern.
Examples
5 AND 3 = 0b101 & 0b011 = 0b001 = 1
5 OR 3 = 0b101 | 0b011 = 0b111 = 7
5 XOR 3 = 0b101 ^ 0b011 = 0b110 = 6
~0 (32u) = 0xFFFFFFFF = 4294967295
~0 (32s) = 0xFFFFFFFF = -1 (two's complement)
1 SHL 4 = 0b10000 = 16
-1 SHR 4 (32s, arithmetic) = -1 (sign-extend)
-1 USHR 4 (32u, logical) = 0x0FFFFFFF = 268435455
0xFFFFFFFF AND 0xFF = 0xFF = 255
Common use cases
- Bit masks and flags: AND with a mask extracts a field; OR sets a flag; XOR toggles one.
- Networking: netmask AND of an IP yields the network address; XOR is used in many CRC and checksum algorithms.
- Cryptography: XOR is the heart of stream ciphers and many block-cipher building blocks.
- Permissions and bit fields: Unix file modes (octal 0755) combine read/write/execute bits with OR.
- Graphics: pack RGBA channels into a 32-bit pixel; extract them with shifts and AND.
- Low-level optimization:
n & (n − 1)clears the lowest set bit;x >> 1is faster than dividing by 2 on most ISAs.
Modes
- Compute: apply a bitwise operation to two operands (one for NOT, an integer shift count for SHL/SHR/USHR). Inputs accept bases 2, 8, 10, and 16, with optional leading
0x/0b/0oprefixes. - Parse: a quick converter — enter a value in any base, get binary, octal, decimal, and hexadecimal back in one shot.
References
- Bitwise operation (Wikipedia) — operator semantics and history.
- Two's complement — how signed integers are encoded.
- MDN: bitwise operators — the JS-specific 32-bit semantics underpinning the 32-bit path.
- Sean Anderson's bit twiddling hacks — canonical reference for low-level idioms.
Notes
- All arithmetic runs in your browser. The same TypeScript module powers the API endpoint below — identical results from either path.
- Shift counts must satisfy
0 ≤ b < width. Native CPU and JavaScript semantics silently mask the count modulo the width, which is surprising; this tool throws instead so you can catch the bug. - 64-bit math uses BigInt for exact results across the entire 64-bit range.
API Usage Example:
POST /api/tools/math/bitwise-calculator
Content-Type: application/json
{
"operation": "and",
"a": "5",
"b": "3",
"aBase": 10,
"bBase": 10,
"width": 32,
"signed": false
}