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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 30 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply