+ 3
Bitwise operators
What are these bitwise operators? How can they be used? bitwise and & bitwise or | bitwise complement ~ bitwise XOR ^ I cannot understand them even after some surfing.
3 odpowiedzi
+ 6
9 in binary is 1001, 3 in binary is 0011, so I will try to align them as follows,
1001
0011
From the four binary numbers, you can assume that 1 is true, 0 is false. So, 9 & 3 will be 0001, which is 1.
Similary, 9 | 3 will be 1011 which is 11.
9 ^ 3 will be 1010 which is 10.
~9 will be 0110.
To be honest, I don't even know what's the use of this...
(In case you don't know XOR, XOR works if both inputs are different.)
+ 1
I written simple program to demonstrate these operators. so please in my code playground(logical gates in c++) and let me know if you have doubt or not clear with the concepts. Then elaborate it further.
Hope it will be useful and understand the concept well and good
+ 1
bitwise operators are special type of operators that first convert your given operands(numbers) into binary and then apply the operator ......eg
lets say we have 2 nos. viz. 10 and 12.
let us apply bitwise AND...
Binary equivalent of 10 is 1010
and that of 12 is 1100
now we will apply AND bit by bit as follows....
10 & 12 is evaluated as follows :
1 AND 1 is 1
0 AND 1 is 0
1 AND 0 is 0
0 AND 0 is 0
thus answer is 1000
now converting this binary number into decimal number we get 8
thus 10 & 12 gives 8
Similarly OR and XOR can be applied.....
Hope this helps...
Any doubt.....do ask!