Ad
  • Custom User Avatar

    If sum=12 in add_binary method, then place_holder in the while loop first takes the value of 3 and then it takes the value of 2. Hence number = 0 + 10^3 + 10^2 = 1100 and sum = 12 - 2^3 - 2^2 = 0 thus exiting the loop. Run over your logic again.

  • Custom User Avatar

    That's not right. Suppose the input is 12, the out put is 1011.2, the correct answer is 1100.