- 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))

10th Apr 2021, 7:02 AM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
4 Antworten
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
10th Apr 2021, 7:39 AM
Vadivelan
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..
10th Apr 2021, 7:47 AM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
0
You mess something bro😇
22nd Sep 2021, 8:36 AM
Juan Mas
Juan Mas - avatar