Question: we developed an algorithm for converting from binary to decimal. You can generalize this algorithm to work for a representation in any base. Instead

we developed an algorithm for converting from binary to decimal. You can 

we developed an algorithm for converting from binary to decimal. You can generalize this algorithm to work for a representation in any base. Instead of using a power of 2, this time you use a power of the base. Also, you use digits greater than 9, such as A... F, when they occur. In convert.py, define a function named repToDecinal that expects two arguments, a string, and an integer. The second argument should be the base. For example, repToDectnal("10". 8) returns 8, whereas repToDectnal("18", 16) returns 16. The function should use a lookup table to find the value of any digit. Make sure that this table (it is actually a dictionary) is initialized before the function is defined. For its keys, use the 10 decimal digits (all strings) and the letters A... F(all uppercase). The value stored with each key should be the integer that the digit represents. (The letter A associates with the integer value 10, and so on.) The main loop of the function should convert each digit to uppercase, look up its value in the table, and use this value in the computation. Include a natn function that tests the conversion function with numbers in several bases. An example of natn and correct output is shown below: def nain(): print(repToDecimal('10', 10)) print(repToDectmal('10', 8)) print(repToDecimal('10'. 2)) print(repToDecinal('16', 16)) 10 8. 2. 16

Step by Step Solution

3.25 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

lookup 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 11 12 D 13 E 14 F ... View full answer

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 Accounting Questions!