What is bit-by-bit operation?
I've read a few things here in Stack Overflow, but I didn't quite get it.
What is bit-by-bit operation?
For example, in context:
Considering the bit-by-bit operation 15^3, the result will be:
0
1 answers
Explanation
The question is: what does 15 ^ 3
or 15 xor 3
mean bit by bit?
First we convert 15 and 3 of the decimal base to binary base:
15 : 1111
3 : 0011
How does XOR work?
XOR or 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 the 15 binary vertically and proceed the XOR operation bit by bit
Bit A B XOR
1 1 1 | 0
2 1 1 | 0
3 1 0 | 1
4 1 0 | 1
I.e. the result of 0b1111 xor 0b0011
is 0b1100
, in decimal is 12.
6
Author: William John Adam Trindade, 2018-07-16 20:15:52