Page 1 of 1

Given five input numbers, a, b, c, d and n, print out the number of 1 bits at the nth least significant bit position in

Posted: Thu Jul 14, 2022 2:13 pm
by answerhappygod
Given five input numbers, a, b, c, d and n, print out the numberof 1 bits at the nth least significant bit position in all fournumbers a, b, c, d. In my code it only satisfy some of the examplebut not all of them, any suggestion on what to change or add?
My Code-
number = input()numbers=number.split()
val1=int(numbers[1])val2=int(numbers[2])val3=int(numbers[3])val4=int(numbers[3])val5=int(numbers[-1])#Extract the lsb from each valuenum1=val1&1num2=val2&1num3=val3&1num4=val4&1num5=val5&1
#Add all the lsb
sum = num1+num2+num3+num4+num5print(sum)
Given Five Input Numbers A B C D And N Print Out The Number Of 1 Bits At The Nth Least Significant Bit Position In 1
Given Five Input Numbers A B C D And N Print Out The Number Of 1 Bits At The Nth Least Significant Bit Position In 1 (151.68 KiB) Viewed 31 times
Given five input numbers, a,b,c,d and n, print out the number of 1 bits at the nth least significant bit position in all four numbers a, b, c, d. Criteria: Example input I 11110 Example output 4 All numbers a,b,c and d are 1 - binary equivalent of which is 0001 . Since n is 0 in the input, nth Isb position is the last bit position. In all four number the last bit position is 1, counting them results in 4.