Home/Developer Tools/Bitwise Calculator

Bitwise Calculator

AND, OR, XOR, NOT and bit-shift two numbers with the binary shown

Free · No sign-up required

Operating on the bits, not the numbers

Bitwise operators treat a number as a sequence of individual binary digits and act on each bit position independently, which is a completely different operation from the arithmetic you normally do with numbers. This calculator runs AND, OR, XOR, NOT, and left and right shift on two numbers, showing the binary and hexadecimal result alongside the decimal one — the binary view is the part that actually explains what happened.

The operators

OperatorRule per bitCommon use
AND (&)1 only if both bits are 1Masking — isolating specific bits, like checking permission flags
OR (|)1 if either bit is 1Combining flags — setting one or more bits without disturbing others
XOR (^)1 if the bits differToggling bits, simple checksums, and the classic swap-two-values-without-a-temp trick
NOT (~)Flips every bitBitwise inversion — note this also flips the sign bit for signed integers
Left shift (<<)Shifts bits left, filling with 0Multiplying by a power of two: n << 1 equals n × 2
Right shift (>>)Shifts bits rightDividing by a power of two: n >> 1 equals n ÷ 2, rounded down

A worked example: AND as a mask

12 & 10 — 12 is 1100 in binary, 10 is 1010. Comparing bit by bit: only the leftmost bit is 1 in both, so the result is 1000, which is 8. This exact pattern — AND against a specific bit pattern — is how permission systems commonly check "is this one specific flag set" without caring about any of the other bits.

Where bitwise operations actually show up

  • Permission and flag systems. Unix file permissions, CSS media query internals, and many configuration systems pack several true/false flags into one integer, combined with OR and checked with AND.
  • Networking. Subnet masks are literally a bitwise AND applied to an IP address to find its network portion.
  • Graphics and colour. Packing RGB or RGBA values into a single 32-bit integer, and unpacking them, is done entirely with shifts and AND masks.
  • Fast arithmetic. Shifting is a cheap way to multiply or divide by powers of two, occasionally still used in performance-sensitive code.
  • Hash functions and checksums. XOR in particular is a building block in many simple hashing and error-detection schemes.

Frequently asked questions

Why is my NOT result negative?

NOT flips every bit including the sign bit, and most programming languages use two's complement representation for negative numbers, where flipping all the bits of a positive number produces a negative one. This is expected, not a bug.

What's the difference between >> and an unsigned right shift?

A plain right shift preserves the sign bit when shifting a negative number, so it stays negative. An unsigned (logical) right shift fills with 0 regardless of sign, which some languages expose as a separate operator (like >>> in JavaScript).

Why does left-shifting sometimes give a surprising result?

Shifting far enough left can overflow the number's bit width — in JavaScript specifically, bitwise operators work on 32-bit integers, so shifting past that width wraps around rather than growing indefinitely.

Is XOR really used for anything practical, or is it just a classroom example?

Very practical — simple checksums, toggling display state, and even the classic trick of swapping two variables without a temporary one all rely on it, alongside heavier use in real cryptographic algorithms.

Can I use negative numbers as input?

Yes — they're represented in two's complement form, same as any programming language's native integer bitwise operations.

Is my data sent anywhere?

No. The calculation runs entirely in your browser.

More tools in this category

🔐
Base64 Encoder & Decoder
Encode and decode text in Base64 format
🔢
Number Base Converter
Convert between binary, decimal, hex, octal and text
📤
Gzip / Deflate Decompressor
Decompress a .gz or raw deflate file back to its original bytes
🌐
IP Address Converter
Convert an IPv4 address between dotted decimal, binary, hex and integer
🔡
Text to ASCII / Binary / Hex
Convert text to ASCII codes, binary, hex or decimal and back
🔢
Word Counter
Count characters, words, sentences, paragraphs and lines