Bitwise Calculator - AND, OR, XOR, NOT, Shift Operations
Math Calculators
Calculate width-limited bitwise AND, OR, XOR, NOT, and shifts for 8, 16, 32, or 64-bit values with exact decimal, hex, and binary results.
Bit width
32-bit binary (groups of 8):
How to use this tool
- Choose an 8-, 16-, 32-, or 64-bit width, then enter complete decimal, hexadecimal, or binary values that fit.
- Select AND, OR, XOR, NOT, left shift (<<), logical right shift (>>>), or arithmetic right shift (>>); shifts use a count from 0 through width minus one.
- Read the exact unsigned decimal, signed two’s-complement decimal, hexadecimal, octal, and width-padded binary result.
Bitwise operators reference
| Operation | Symbol | What it does | Example |
|---|---|---|---|
| AND | & | 1 when both bits are 1 | 0101 & 0011 = 0001 |
| OR | | | 1 when either bit is 1 | 0101 | 0011 = 0111 |
| XOR | ^ | 1 when the bits differ | 0101 ^ 0011 = 0110 |
| NOT | ~ | Flips every bit in the selected width | ~00000101 = 11111010 (8-bit) |
| Left shift | << | Moves bits left; high bits are discarded | 0101 << 1 = 1010 |
| Logical right shift | >>> | Moves bits right and fills high bits with 0 | 11000000 >>> 1 = 01100000 (8-bit) |
| Arithmetic right shift | >> | Moves bits right and extends the sign bit | 11000000 >> 1 = 11100000 (8-bit) |
Choose an explicit width of 8, 16, 32, or 64 bits. The calculator parses complete decimal,
hexadecimal, and binary tokens, then applies each operation to a bit pattern of exactly that
width. Decimal input may range from −2^(width−1) through 2^width−1; prefixed hexadecimal and
binary inputs are unsigned patterns that must fit. Inputs outside those bounds and incomplete
tokens such as 0x are reported inline instead of being silently truncated or partially
parsed. Results include unsigned decimal, signed two’s-complement decimal, hex, octal, and a binary
grid padded to the selected width.
A shift count must be a whole number from zero through one less than the selected width. Thus an 8-bit value accepts shifts from 0 to 7, and a 64-bit value accepts shifts from 0 to 63. This explicit validation avoids JavaScript’s usual modulo-32 shift-count behavior. Left shifts discard bits that move beyond the high end of the selected pattern, so the displayed result always remains exactly the chosen width.
Common uses in programming
- Permission flags: Linux file permissions use bitwise OR to combine read (4), write (2), and execute (1).
- Moving bits: a left shift by n positions moves bits toward higher powers of two. Right shifts move them toward lower positions; for nonnegative values, shifting right by n corresponds to integer division by 2ⁿ.
- Checking even or odd:
n & 1is 1 for odd values and 0 for even values. - Masking bits: AND a value with a mask to isolate selected flags, fields, or network-address bits.
Two’s complement and the NOT operator
Two’s complement gives each fixed-width pattern both an unsigned value and a signed
interpretation. For a width of w bits, the most significant bit is the sign bit: when set,
its signed weight is −2^(w−1), while the other bits have positive powers-of-two weights. This explains
why ~5 = -6 in the default 32-bit mode: NOT flips every bit, and in two’s complement
~n equals −(n + 1). At 8 bits, ~0
instead produces 0xFF, whose unsigned value is 255 and signed value is −1.
The width changes the pattern, not just its display. For example, NOT of zero is eight 1 bits
(0xFF) at 8 bits and 64 1 bits (0xFFFFFFFFFFFFFFFF) at 64 bits. Both
patterns have a signed interpretation of −1. This is useful when checking masks and
fixed-width values used by file permissions, binary protocols, or processor registers.
Logical and arithmetic right shift
Logical >>> always fills vacated high bits with zero. Arithmetic
>> copies the selected-width sign bit into those positions, which preserves the
negative two’s-complement interpretation. For an 8-bit pattern 0xC0, logical
>>> 1 yields 0x60, while arithmetic >> 1
yields 0xE0. With 0xFFFFFFFF at 32 bits, logical shift gives
0x7FFFFFFF, while arithmetic shift remains 0xFFFFFFFF. The
calculator uses arbitrary-precision integers internally, so 64-bit values and their decimal
outputs remain exact.
Signed and unsigned interpretations
The unsigned result ranges from 0 through 2^w−1, while the signed two’s-complement interpretation ranges from −2^(w−1) through 2^(w−1)−1 for a width of w bits. These are two ways to read the same fixed-width pattern. In C and C++, right-shifting a negative signed value has historically been implementation-defined (commonly arithmetic), so use unsigned types explicitly when you need portable bit-pattern behavior in another language. This calculator names both right-shift choices so their zero-fill and sign-fill behavior stays clear.
Frequently asked questions
What input formats are accepted?
Use one complete decimal (42), hexadecimal (0xFF), or binary (0b1010) token. Choose 8, 16, 32, or 64 bits first. Decimal inputs may range from -2^(width-1) through 2^width-1; hexadecimal and binary inputs are unsigned bit patterns from 0 through 2^width-1. Values that do not fit are rejected instead of truncated.
What shift amounts can I use?
Left, logical-right, and arithmetic-right shifts accept whole counts from 0 through one less than the selected width. For example, an 8-bit value accepts 0 through 7, while a 64-bit value accepts 0 through 63. Larger counts are rejected, and left-shift bits that leave the selected width are discarded.
What is the difference between >>> and >>?
Logical right shift (>>>) moves bits right and fills vacated high bits with zero. Arithmetic right shift (>>) interprets the selected-width sign bit and fills with that bit, preserving negative values in two’s complement. For an 8-bit 0xC0 shifted right once, logical >>> gives 0x60 and arithmetic >> gives 0xE0.
Related tools
- Number Base ConverterConvert operands between decimal, binary, octal, and hexadecimal before masking.
- Truth TableInspect Boolean outcomes one bit at a time before applying them to integers.
- Modular ArithmeticCompare bit-level operations with powers, remainders, and modular inverses.
- Hex Dump ViewerInspect real file bytes in hexadecimal before applying masks or shifts.