Question: In a file binary.py, write a recursive function bin_to_int that takes an unsigned binary value (as a string like 100101) and converts it to an

In a file binary.py, write a recursive function bin_to_int that takes an unsigned binary value (as a string like "100101") and converts it to an integer (37 in the example).

This can be done recursively for any length binary string. In the example ("100101"), notice that the first 5 characters of the string ("10010") convert to the integer 18 and the last character ("1") becomes 1. Therefore, the whole string converts to 37 = 218 + 1.

So, you should first convert the first n-1 bits to a decimal value, double it, and add the last bit.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!