The operator & is another bitwise operator int C++. For making let's call the bits names. 0-false and 1 -true.
First let's look at an example
000000011100
&
000000000101
Let's remember the logical operator if. Just like the && (and) operator in if , the bitwise operator & (and) has the same meaning. When we had a conditional operator if and 2 conditions in it .
Let's have a loot at this chart
for operator && in if statement
condition 1 condition 2 result
false false false
true false false
false true false
true true true
So basically , if both of the conditions are true => the if statement is true otherwise its false. Just like && the operator & does the same but with bits.
for bitwise operator &
bit1 bit2 result
0 0 0
1 0 0
0 1 0
1 1 1
Remember that 0 stands for false and 1 stands for true
So in our example from the beginning , when we perform the operator & we get
000000011100
&
000000000101
=
000000000100
First let's look at an example
000000011100
&
000000000101
Let's remember the logical operator if. Just like the && (and) operator in if , the bitwise operator & (and) has the same meaning. When we had a conditional operator if and 2 conditions in it .
Let's have a loot at this chart
for operator && in if statement
condition 1 condition 2 result
false false false
true false false
false true false
true true true
So basically , if both of the conditions are true => the if statement is true otherwise its false. Just like && the operator & does the same but with bits.
for bitwise operator &
bit1 bit2 result
0 0 0
1 0 0
0 1 0
1 1 1
Remember that 0 stands for false and 1 stands for true
So in our example from the beginning , when we perform the operator & we get
000000011100
&
000000000101
=
000000000100
No comments:
Post a Comment