Bitwise XOR Calculator: A ^ B in Decimal, Binary and Hex

Bitwise XOR Calculator

Compute A XOR B where every output bit is 1 only when the two input bits differ. Enter operands in decimal, binary, or hex, then read the result in all three bases, see the aligned bit-by-bit XOR column, count the differing bits (Hamming distance), and flip bits with a toggle mask.

Quick XOR Presets

🔢XOR Inputs

The first number. Interpreted using the base you pick beside it.

How to read Operand A. Hex may use an optional 0x prefix.

The second number. In mask mode its 1-bits flip the matching bits of A.

How to read Operand B or the mask value.

Number of bit columns shown in the aligned XOR view.

Toggles the aligned A / B / result binary breakdown.

Same math either way; this reframes B as a bit-flip mask over A.

Chooses which base the status line calls out first.

XOR result (decimal) 0 A ^ B in base 10
Result binary 0 grouped in nibbles
Result hex 0x0 base 16 form
Differing bits 0 Hamming distance, parity even

📈XOR at a Glance

^XOR operator
1↔1=0same bits cancel
A^A=0self inverse
A^0=Azero identity

🔑1-Bit XOR Truth Table

Bit ABit BA ^ BBits Match?Meaning
000YesSame, output 0
011NoDiffer, output 1
101NoDiffer, output 1
110YesSame, output 0

📑XOR Identities and Properties

PropertyRuleExampleWhy It Matters
Self-cancelA ^ A = 06 ^ 6 = 0Duplicate detection, reset
Zero identityA ^ 0 = A6 ^ 0 = 6Leaves value unchanged
Own inverseA ^ B ^ B = A6 ^ 10 ^ 10 = 6Encrypt then decrypt
CommutativeA ^ B = B ^ A12 ^ 10 = 10 ^ 12Order does not matter
Associative(A^B)^C = A^(B^C)chained foldsFold a whole array
Flip maskA ^ 0xFFflips all 8 bitsInvert selected bits
Toggle bit nA ^ (1 << n)A ^ 32 flips bit 5Switch one flag

🗃XOR Comparison Grid

ABA ^ B (dec)Binary (8-bit)Diff BitsUse Case
121060000 01102Basic difference
255170850101 01014Alternating mask
424200000 00000Self cancels
20002001100 10000Zero identity
1502551050110 10018Flip all bits
532370010 01011Toggle bit 5
6532970110 00011ASCII A to a
722031311000 00114Cipher byte
240152551111 11118Nibble merge
7700000 00000Parity of pair

🌐Common Byte Masks

MaskHexBinaryXOR Effect on A
All ones0xFF1111 1111Flip every bit (NOT)
High nibble0xF01111 0000Flip top 4 bits only
Low nibble0x0F0000 1111Flip bottom 4 bits
Alternating0xAA1010 1010Flip odd-index bits
ASCII case0x200010 0000Swap letter case
Single bit 00x010000 0001Toggle least bit
Sign bit (8)0x801000 0000Flip highest bit

Formula Breakdown

result = A ^ BLine the operands up bit for bit. Each output bit is 1 when the two bits differ, and 0 when they match, so 0^0=0, 1^1=0, 0^1=1, and 1^0=1.
Worked case 12 ^ 1012 is 1100 and 10 is 1010. Column by column: 1^1=0, 1^0=1, 0^1=1, 0^0=0, giving 0110 = 6 in decimal, 0x6 in hex.
Differing bitsCount the 1s in A ^ B. That popcount is the Hamming distance, the number of positions where A and B disagree. For 12 ^ 10 = 6 = 0110 there are two set bits, so the distance is 2.
Parity of resultIf the result has an even number of set bits its parity is even, otherwise odd. XOR-folding every bit of a value collapses it to a single parity bit.
Self inverseBecause A ^ A = 0 and A ^ 0 = A, applying the same operand twice cancels: A ^ B ^ B returns the original A. This is why XOR encrypts and decrypts with one key.
Toggle with a maskA ^ mask flips exactly the bits that are 1 in the mask and leaves the rest alone. Using mask = 1 << n flips a single bit n, a clean way to switch one flag on or off.
Swap without tempa ^= b; b ^= a; a ^= b exchanges two variables using no extra storage, a direct consequence of XOR being its own inverse.

💡Practical XOR Tips

Toggle, do not test-and-set: To flip bit n use value ^ (1 << n) in one operation instead of reading the bit, deciding, and writing it back. XOR always inverts the target bit, so value ^ 32 switches bit 5 whether it was 0 or 1, and a second XOR with 32 puts it right back.
Find the odd one out: XOR every element of a list together. Because A ^ A = 0, all values that appear an even number of times cancel, and the single unpaired value survives. In a list where one number appears once and every other appears twice, one left-to-right XOR pass reveals it in O(n) time and no extra memory.

Bitwise XOR compares two number digit-by-digit; if they don’t match, it return a 1 (flipping a flag). That means that the XOR operator is good for detecting differences… A difference calculator. The beauty of it is that it removes abstraction. You can drop in whatever number you want in whichever base (hex, binary, or decimal). It will return the answer in all three and show them lined up visually in a column.

This makes it easier to follow the rule along with your finger until it stick in your head, instead of being another forgotten quirk of the syntax. The operation is called exclusive-or and is defined by applying it to the bits in each column of a number, one column at a time. It is straightforward. Zero XOR zero equals zero. One XOR one equals zero. Zero XOR one equals one. One XOR zero equals one. Put another way, the output bit will light up if the two input bits aren’t alike.

What Is Bitwise XOR?

You can check if either bit is set (the inclusive OR), or you can check if they are both set (AND). But if you care about parity shift or a flag flipping, or any question of change, you’d ask with XOR because it cares about differences. Put 10 and 12 in the tool and it will line them up as 1010 and 1100 and work through each column resolving where they don’t match. The answer is 0110, which is six in decimal. This means the answer shows where numbers disagree.

Four metrics are calculated with each operation and displayed differently. First, the decimal answer is shown in decimal format, which is how you would typically program this in most languages. Second, it’s shown in binary but grouped into nibbles so you can still read long numbers. Third, it’s expressed in hexadecimal, the base used by engineers when they’re talking about colors and memory addresses. Fourth, it’s the Hamming distance between your two operands, otherwise known as the number of differing bits.

It will tell you the number of differences but also whether it’s an odd or even difference. Because one wrong bit flipped could trash a transmission unless you catch it early, parity is important for error checking. What XOR does isn’t always apparent from numbers alone. The calculator presents the operands in an aligned grid, drawing them above and below each other. Result is shown under those, padded to whatever number of bits you prefer; eight, sixteen, or thirty-two. The highlighted positions make it clear right away which columns has changed, turning a mental puzzle into something you can see.

If you’d like to flip some bits in A, you can set the second operand as a mask. XORing a bit with zero leaves it unchanged. XORing with one inverts it. This way, you create a mask where the ones indicate which bits to change. To flip a single bit, then, you simply use a mask with a one shifted left by the number of positions representing the bit you wish to flip. Apply the same mask again and it will cancel out entirely, which is clean and reversible.

Most of what XOR comes up in practice can be explained by a few identities. If you apply it to any value with the same bits, it will return zero (e.g., A XOR A = 0). If you apply it to anything and zero, then you’ll get back whatever was there at first (e.g., A XOR 0 = A, since nothing is different than nothing). Because XOR is associative and commutative, applying it in chains doesn’t matter. The groupings do not matter. The order does not matter.

You can take some array and fold it into a single value. The duplicates cancel in pairs, leaving only the unpaired survivor. Only the one that isn’t paired will remain. It’s a little trick that’s linear time and memory efficient. Best of all, you can encrypt messages with a cipher where decrypting is the exact same operation as encrypting because A XOR B XOR B gives you back A! That self-cancelling trait is how those simple ciphers work.

Preset mappings from this page correspond to actual use cases in hardware logic or systems programming tasks. Stream ciphers, which encrypt using a key and then decrypt by doing the same thing again, are based on the inverse property. Without any branching logic, flipping the case bit (with 0x20) switches between upper- and lower-case letters. You can create a checksum by taking all the bits of a value and folding them into one parity bit. This process depends on such a fold.

Each operand can have its own choice of input base, making natural mixing between variables expressed in decimal and constants written out as hex. Finally, you can set how wide each value is displayed, allowing you to examine either a thirty-two-bit word or an eight-bit byte in an aligned format. This keeps the binary representation looking nice and clean, but under the hood the tool will mask values to match the chosen width.

Seeing the bits line up is the quickest path to building that intuition. XOR rewards understanding rather than memorization. Whether you’re trying to explain the swap trick or debug a flag register, having the answer in binary, decimal, and hex helps. It bridges the gap between high-level world of logic and the low-level world of reality. Enter two numbers and read the result. Watch how the pattern of difference reveals itself when looked at closely.

The magic isn’t in the operation itself; it is in the pattern of difference that reveals itself when you look closely enough. You should of seen the bits line up sooner if you used the tool.

Bitwise XOR Calculator: A ^ B in Decimal, Binary and Hex