Question

In Python, For these functions do not use built functions such as hex() and bin() to...

In Python, For these functions do not use built functions such as hex() and bin() to solve the problem. binaryToInt ( String ) : int • Takes a string of 16 0s and 1s and returns an integer corresponding integer in the range 0-65535

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def binaryToInt(b_string):
    result = 0
    length = len(b_string)
    for i in range(0, length):
        if(b_string[i] == '1'):
            result += 2**(len(b_string)-i-1)
    return result


# Testing
print(binaryToInt("0000000011010101"))

213

Add a comment
Know the answer?
Add Answer to:
In Python, For these functions do not use built functions such as hex() and bin() to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT