What is bit-a-bit operation?

Asked

Viewed 237 times

0

I’ve read some things here at Stack Overflow, but I don’t quite understand.

What is bit-to-bit operation?

For example, in the context:

Considering bit-to-bit operation 15 3, the result will be:

1 answer

6


Explanation

The point is, what does it mean 15 ^ 3 or 15 xor 3 bit by bit?

First we convert 15 and 3 of the decimal base into binary basis:

15 : 1111
 3 : 0011

How the XOR works?

Xor or OR Exclusive (or exclusive) is true if bits A B are different and false if they are equal, which gives this table

A B  XOR
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 0

Now you have to pair the 3 and 15 binary vertically and perform the bit-to-bit XOR operation

Bit  A B  XOR
1    1 1 | 0 
2    1 1 | 0
3    1 0 | 1
4    1 0 | 1

That is, the result of 0b1111 xor 0b0011 is 0b1100, decimally is 12.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.