snippetMinor
How to XOR two binary numbers having different lengths?
Viewed 0 times
xornumbershavingdifferenttwobinarylengthshow
Problem
If we have:
x = 1101 and y = 101
How to XORing these numbers?
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.
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.
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
1000which 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
1000Context
StackExchange Computer Science Q#48614, answer score: 4
Revisions (0)
No revisions yet.