+ 9
& in python
why is bool(1&2) false aren't both numbers true
7 Respostas
+ 8
& is a bitwise AND
1 in 4 bit binary is 0001
2 in 4 bit binary is 0010
0001
0010 &
--------
0000 = 0 = false
With a bitwise & both bits must be 1 to result in 1 otherwise the bit is 0
+ 9
thanks for clearing that up @sayan I will sure do
+ 7
thanks now I understood
+ 7
@shaikh salman you mean bool(1&2) ,bool(1|2) ,I mean isn't "and" , and "or" in their literal form do normal logical operations ,while binary operators &,| do binary comparison , please correct me if I'm wrong I really thought I got it.
+ 6
....
1 = 01
2 = 10
and(&) together go to "0"
....?
bool(1 and 2) perhaps?
bc & is binary operator
0
& is logical AND
as in AND gates
## Truth table..
A B Y=A.B
0 0 0
1 0 0
0 1 0
1 1 1
bool of 0 is false
bool of anything else is true(positive or negetive number)
other logical opeeators are
>> << ~ | ^
(google them)
0
1&2
-> 0001 & 0010
-> (0.0)(0.0)(0.1)(1.0)
-> 0000-> false