HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to XOR two binary numbers having different lengths?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
xornumbershavingdifferenttwobinarylengthshow

Problem

If we have:

x = 1101 and y = 101

How to XORing these numbers?

Solution

There are multiple ways to interpret this XOR.

The most common one is that you XOR bit-wise, and that these strings represent numbers, so adding 0 to the left doesn't change their value.

Then $5 \equiv 101 \to 0101$ and then you XOR bit-wise.

x 1101
y 0101
------- XOR
  1000


which gives 8, if we are talking about unsigned numbers.
However, the above depends on my understanding of your system. Change the assumptions, change the results.

Code Snippets

x 1101
y 0101
------- XOR
  1000

Context

StackExchange Computer Science Q#48614, answer score: 4

Revisions (0)

No revisions yet.