Perform bitwise operations on integers including AND, OR, XOR, NOT, and bit shifts. Essential for low-level programming and digital logic.
2026-03-28T00:00:00Z
Bitwise operations are operations that directly manipulate bits, which are the smallest units of data in computing. These operations work at the binary level, treating numbers as sequences of bits (0s and 1s) rather than decimal values.
Bitwise operations are fundamental in computer science and are used extensively in low-level programming, embedded systems, cryptography, graphics programming, and performance optimization. They allow programmers to perform operations much faster than arithmetic operations and can reduce memory usage.
Common bitwise operations include AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). Each operation has specific uses, from setting and clearing flags to multiplying or dividing by powers of two.
Input Validation: This calculator requires valid integers for all inputs. Decimal values are truncated to integers (the decimal part is discarded). Empty or non-numeric inputs are rejected with an error message.
Returns 1 only if both bits are 1. Used for masking and checking if specific bits are set.
Returns 1 if either bit is 1. Used for setting bits and combining flags.
Returns 1 if bits are different. Used for toggling bits and simple encryption.
Inverts all bits (0 becomes 1, 1 becomes 0). Creates the bitwise complement. Note: NOT requires only one operand (Number 1); Number 2 is ignored.
Shifts bits left N positions (where N = Number 2), filling with zeros. Equivalent to multiplying by 2^N.
Shifts bits right N positions (where N = Number 2), discarding rightmost bits. Equivalent to dividing by 2^N and rounding down.
Let's perform 12 & 5:
& is a bitwise AND that operates on individual bits, while && is a logical AND that operates on boolean values. The single & always evaluates both operands, whereas && short-circuits if the first operand is false.
The NOT operator inverts all bits. In two's complement representation (used for signed integers), inverting all bits of a positive number n gives -(n+1). So ~12 = -(12+1) = -13.
Left shift by n positions multiplies by 2^n. For example, 5 << 2 = 5 × 4 = 20. Right shift by n divides by 2^n and rounds down. This makes shifts faster than multiplication/division operations.
Bit masking uses AND operations to extract specific bits from a number. For example, n & 0xFF extracts the lowest 8 bits. It's commonly used to isolate specific data within a packed integer.
XOR is useful for toggling bits (x ^ 1 toggles the least significant bit), swapping values without a temporary variable (a ^= b; b ^= a; a ^= b), and simple encryption/checksums.
Yes! Bitwise operations are among the fastest CPU operations. They're often used in performance-critical code, embedded systems, and low-level programming where every cycle counts.
Bitwise operations are used for: setting/clearing flags, permissions systems, network protocols, graphics (color manipulation), compression algorithms, hash functions, and optimizing mathematical operations.
To set bit n: use x | (1 << n). To clear bit n: use x & ~(1 << n). To toggle bit n: use x ^ (1 << n). To check if bit n is set: use (x & (1 << n)) != 0.
Related Tools
Binary arithmetic operations.
Add binary numbers.
Subtract binary numbers.
Multiply binary numbers.
Divide binary numbers.
Convert decimal fractions to binary.