No Login Data Private Local Save

Bitwise Calculator - Online AND OR XOR NOT Shift

5
0
0
0

Bitwise Calculator

Perform AND, OR, XOR, NOT, and bit shift operations with instant binary visualization

Hex: 0x2A • Bin: 00101010
Hex: 0x17 • Bin: 00010111
42 & 23 = ?
2
Decimal
2
Hexadecimal
0x2
Binary (32-bit)
00000000 00000000 00000000 00000010
32-Bit Visualization
A
B
Result
MSB (31) Bit Position LSB (0)
Truth Table Reference
ABANDORXOR
00000
01011
10011
11110
Quick Tips
  • AND – Mask bits (keep only desired bits)
  • OR – Set specific bits to 1
  • XOR – Toggle bits / check parity
  • NOT – Invert all bits (two's complement)
  • << – Multiply by 2n (shift left n)
  • >> – Divide by 2n (arithmetic shift)
  • >>> – Logical shift (zero-fill right)

Frequently Asked Questions

A bitwise operation directly manipulates individual bits within binary representations of integers. Instead of treating numbers as whole values, bitwise operations work on each corresponding pair of bits from two operands (or a single operand for NOT). These operations are fundamental in low-level programming, cryptography, graphics processing, and performance-critical code where direct bit manipulation is faster than arithmetic equivalents.

The AND (&) operation compares each bit pair and returns 1 only when both bits are 1. Otherwise it returns 0. This is commonly used for bit masking—isolating specific bits by ANDing with a mask value. For example, 42 & 15 extracts the lower 4 bits of 42 (since 15 = 0b1111), resulting in 10.

OR (|) returns 1 if at least one bit is 1. It's used to set (turn on) specific bits. XOR (^) returns 1 only when the bits are different (one is 0, the other is 1). XOR is reversible—applying XOR twice with the same value returns the original. This property makes XOR popular in cryptography, checksums, and toggling bits without a conditional branch.

The NOT (~) operator flips every bit: 0 becomes 1 and 1 becomes 0. In two's complement representation (used by JavaScript and most modern systems), ~n equals -(n + 1). For example, ~5 = -6. This is because flipping all bits of 5 (0b...00000101) produces 0b...11111010, which is the two's complement representation of -6. The NOT operation is useful for creating inverted masks and implementing subtraction circuits.

>> (Arithmetic right shift) preserves the sign bit (most significant bit). When shifting right, it fills the leftmost positions with the sign bit. This means negative numbers stay negative. >>> (Logical/unsigned right shift) always fills with zeros from the left, treating the number as unsigned. For positive numbers, both shifts produce the same result. For negative numbers, -8 >> 1 = -4 (still negative), but -8 >>> 1 = 2147483644 (becomes a large positive number).

Bitwise operations map directly to single CPU instructions that execute in typically one clock cycle. They bypass the arithmetic logic unit's more complex pathways used for multiplication and division. For example, x << 3 (multiply by 8) is significantly faster than x * 8 on many architectures. Compilers often optimize multiplication/division by powers of two into bit shifts automatically. This efficiency is critical in embedded systems, game engines, and performance-sensitive applications.

Bitwise operations appear everywhere in computing: flags and permissions (storing multiple boolean options in a single integer), color manipulation (extracting RGB channels from a hex value), hash functions (mixing bits for distribution), network protocols (parsing packet headers with specific bit fields), cryptography (XOR ciphers, S-boxes), data compression (Huffman coding, bit packing), and embedded systems (controlling hardware registers directly). Understanding bitwise operations is essential for any systems-level programmer.

This calculator uses 32-bit signed integer representation, matching JavaScript's native bitwise operation behavior. All inputs are converted to 32-bit signed integers (range: -2,147,483,648 to 2,147,483,647). The binary display shows all 32 bits organized in four 8-bit bytes for readability. For unsigned right shift (>>>), the result is displayed as an unsigned 32-bit integer (range: 0 to 4,294,967,295).