Math Calculators
Bitwise Calculator - AND, OR, XOR, NOT, Shift Operations
Perform bitwise AND, OR, XOR, NOT, left shift, and right shift operations with 32-bit visualization. Input decimal, hex (0x), or binary (0b) values.
32-bit binary (groups of 8):
Bitwise operators reference
| Operator | Symbol | Description | Example (5 op 3) |
|---|---|---|---|
| AND | & | 1 if both bits are 1 | 0101 & 0011 = 0001 (1) |
| OR | | | 1 if either bit is 1 | 0101 | 0011 = 0111 (7) |
| XOR | ^ | 1 if bits differ | 0101 ^ 0011 = 0110 (6) |
| NOT | ~ | Flips all bits | ~0101 = ...11111010 (-6) |
| Left shift | << | Shift bits left (× 2 per shift) | 0101 << 1 = 1010 (10) |
| Right shift | >> | Shift bits right (÷ 2 per shift) | 0101 >> 1 = 0010 (2) |
Common uses in programming
- Permission flags: Linux file permissions use bitwise OR to combine read (4), write (2), execute (1).
- Fast multiplication/division: left shift by n = multiply by 2ⁿ; right shift by n = integer divide by 2ⁿ.
- Checking even/odd:
n & 1- if result is 1, n is odd; if 0, n is even. - Masking bits: isolate specific bits of a value using AND with a mask.
Two's complement and the NOT operator
JavaScript (and most modern processors) stores integers using two's complement
representation for signed 32-bit integers. This explains why ~5 = -6: the NOT
operator flips all 32 bits, and in two's complement, that equals -(n + 1) for any integer
n.
Two's complement makes addition and subtraction work with the same hardware circuit for both positive and negative numbers. The most significant bit acts as the sign bit: 0 = positive, 1 = negative.
Unsigned right shift (JavaScript >>>)
JavaScript's >>> operator is the unsigned right shift.
Unlike
>> (signed shift, which preserves the sign bit), >>>
always fills the vacated high bits with zeros, treating the number as an unsigned 32-bit integer.
For example: -1 >> 0 = -1, but -1 >>> 0 = 4,294,967,295
(0xFFFFFFFF). Use >>> when you need consistent unsigned behavior regardless
of the input's sign.
Signed vs. unsigned integers
In languages like C and C++, integer types can be declared as signed or
unsigned. An unsigned int (32-bit) ranges from 0 to 4,294,967,295; a signed int ranges from −2,147,483,648 to 2,147,483,647. Right-shifting a signed negative value in C produces
implementation-defined behavior (typically arithmetic shift), so use unsigned types explicitly when
you need predictable bit patterns.