Bitwise Xor Calculator

Written by:
PK

Use this bitwise XOR calculator to compare bits and return 1 where they differ. XOR (exclusive OR) is useful for toggling bits, simple encryption, and finding unique values.

Bitwise XOR calculator

Using the calculator

Enter two numbers and select an input format for each: Decimal, Hex, Binary, or Octal. You can also type prefixes directly (0xFF for hex, 0b1010 for binary, or 0o17 for octal) and the tool will auto-detect the format.

The result displays in all formats simultaneously: decimal (signed and unsigned), hexadecimal, octal, and a 32-bit binary representation with spaces every 8 bits for readability.

How bitwise XOR works

Bitwise XOR (exclusive OR, written as ^) compares each bit of two numbers. It returns 1 if the bits are different, and 0 if they are the same. Think of it as "one or the other, but not both."

The XOR truth table:

ABA ^ B
000
011
101
110

Bitwise XOR example

Comparing the binary representations bit by bit:

00101100 (44)
00011000 (24)
────────
00110100 (52)

Positions where the bits differ produce a 1 in the result. In other words: 44 ^ 24 = 52.

Common uses for XOR

Toggle bits: XOR with 1 flips a bit, XOR with 0 keeps it the same. Useful for switching flags on and off.

Simple encryption: XORing data with a key scrambles it; XORing again with the same key recovers the original (since a ^ b ^ b = a).

Swap without temp: You can swap two variables using three XOR operations: a ^= b; b ^= a; a ^= b;

Find unique element: XOR all elements in an array where every element appears twice except one - the result is the unique element.

      

PK

PK started DQYDJ in 2009 to research and discuss finance and investing and help answer financial questions. He's expanded DQYDJ to build visualizations, calculators, and interactive tools.

PK lives in New Hampshire with his wife, kids, and dog.

Don't Quit Your Day Job...

DQYDJ may be compensated by our partners if you make purchases through links. See our disclosures page. As an Amazon Associate we earn from qualifying purchases.
Sign Up For Emails
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram