subject
Computers and Technology, 03.11.2020 06:20 Liapis

In Chapter 4, 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, you will write a program that converts any base between 2 and 16. Recall that for numbers 10 - 15 we use letters A - F. In convert. py, define a function named repToDecimal that expects two arguments, a string, and an integer. The second argument should be the base. For example, repToDecimal("10", 8) returns 8, whereas repToDecimal("10", 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. A main function that tests the conversion function with numbers in several bases has been provided.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 14:30
The basic work area of the computer is it screen that you when you first fire up your computer
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Which boolean operator enables you to exclude a search term? a} not b} and c} or d} plus
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
Suppose a cpu with a write-through, write-allocate cache achieves a cpi of 2. what are the read and write bandwidths (measured by bytes per cycle) between ram and the cache? (assume each miss generates a request for one block.)
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
How can you make your column headings stand out?
Answers: 1
You know the right answer?
In Chapter 4, we developed an algorithm for converting from binary to decimal. You can generalize th...
Questions
question
Mathematics, 17.03.2021 23:40
question
Mathematics, 17.03.2021 23:40
question
English, 17.03.2021 23:40