Skip to content
Toolcroft

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

Decimal: 8
Signed: 8
Hex: 0x00000008
Oct: 10

32-bit binary (groups of 8):

A =12 (0x0000000C)
B =10 (0x0000000A)

How to use this tool

  1. Choose an 8-, 16-, 32-, or 64-bit width, then enter complete decimal, hexadecimal, or binary values that fit.
  2. Select AND, OR, XOR, NOT, left shift (<<), logical right shift (>>>), or arithmetic right shift (>>); shifts use a count from 0 through width minus one.
  3. Read the exact unsigned decimal, signed two’s-complement decimal, hexadecimal, octal, and width-padded binary result.

Bitwise operators reference

OperationSymbolWhat it doesExample
AND&1 when both bits are 10101 & 0011 = 0001
OR|1 when either bit is 10101 | 0011 = 0111
XOR^1 when the bits differ0101 ^ 0011 = 0110
NOT~Flips every bit in the selected width~00000101 = 11111010 (8-bit)
Left shift<<Moves bits left; high bits are discarded0101 << 1 = 1010
Logical right shift>>>Moves bits right and fills high bits with 011000000 >>> 1 = 01100000 (8-bit)
Arithmetic right shift>>Moves bits right and extends the sign bit11000000 >> 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 & 1 is 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.

Browse all math calculators