Can anyone explain this?? | Sololearn: Learn to code for FREE!

-1

Can anyone explain this??

l = [] for i in range(17): l.append(i*2) m = [x&1 for x in l] print(sum(m))

4/10/2021 7:02:09 AM

Mohammad Mehedi Hasan

4 Answers

New Answer

0

range(17) gives 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16. Each value multiple itself(0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256). And add to list l. Each value of list l do Bitwise AND(&) operation. It gives 1 if both value is 1 otherwise 0. Convert each values into binary then compare with 1 Example: 25 -> 00011001 1 -> 00000001 & ---------------------- 00000001 = 1 The 1 is added to list m. All values of list l gives the following result to m after bitwise AND operation [0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1] Then sum these values, it gives 8. https://www.sololearn.com/learn/4072/?ref=app https://www.sololearn.com/learn/4070/?ref=app

0

Ehem.. Vadivelan, I am sorry man, i*2 not i**2.. Can you please share any link where I can learn about bit.. I mean how 21 = 0011..?? From beginning..

0

https://www.rapidtables.com/convert/number/decimal-to-binary.html

0

You mess something bro😇