What is bit-a-bit operation?

0

I have read some things here in Stack Overflow, but I did not quite understand it.

What is bit-to-bit operation?

For example, in the context:

  

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

    
asked by anonymous 16.07.2018 / 21:31

1 answer

6

Explanation

The question is: What does 15 ^ 3 or 15 xor 3 bit by bit mean?

First convert 15 and 3 decimal base into binary base:

15 : 1111
 3 : 0011

How does XOR work?

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 carry out the bitwise 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 , in decimal it is 12.

    
16.07.2018 / 21:48