+ 2

what does it mean in python: i&1

Please, help to understand instruction

22nd Jan 2018, 6:03 AM
Алексей Шмуйлович
Алексей Шмуйлович - avatar
5 Answers
+ 5
with 7 111&101 = 101 or 5, with 8 or 1000&0101 = 0000 or 0
22nd Jan 2018, 6:22 AM
John Wells
John Wells - avatar
+ 4
it is binary "and". Eg 7 = 111 111 and 001 = 1 Actually it is a test if a number i is odd. if yes, the result is 1.
22nd Jan 2018, 6:18 AM
Oma Falk
Oma Falk - avatar
+ 3
& is the bit and operator. i&1 is 0 for even numbers and 1 for odd. if i is 5, 101&001=001 as that is the only bit that is 1 in both numbers.
22nd Jan 2018, 6:16 AM
John Wells
John Wells - avatar
+ 2
Thank you. And what is i&5, for example?
22nd Jan 2018, 6:20 AM
Алексей Шмуйлович
Алексей Шмуйлович - avatar
+ 1
Hey, MR. JOHN WELLS I LIKE YOUR KNOWLEDGE AND EXPERIENCE IN THIS FIELD, Is there any way I can contact you, as I want to be your student.... 🙏🙏🙏
22nd Jan 2018, 4:56 PM
Shalin Suthar
Shalin Suthar - avatar