Ask Question
28 March, 22:02

5 write a recursive method that returns the number of 1's in the binary representation of n. use the fact that this is equal to the number of 1's in the representation of n/2, plus 1, if n is odd.

+5
Answers (1)
  1. 28 March, 22:30
    0
    Assuming n is a decimal number.

    Divide n by 2 repeatedly, and summing the remainders will give the number of one's in binary representation.

    pseudocode of algorithm:

    Enter value of n:

    sum=0;

    while n>0 {

    sum=mod (n, 2);

    n=n/2 [integer division]

    }

    Display n, sum
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “5 write a recursive method that returns the number of 1's in the binary representation of n. use the fact that this is equal to the number ...” in 📗 Mathematics if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers