we developed an algorithm for converting from binary to decimal. You can generalize this algorithm to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Posted Date:
Students also viewed these accounting questions
-
In Section 4.10 we developed an algorithm for multiplying signed binary fractions, with negative fractions represented in 2s complement. (a) Illustrate this algorithm by multiplying 1.0111 by 1.101....
-
Researchers at Carnegie Mellon University developed an algorithm for estimating the sensor motion of a robotic arm by mounting a camera with inertia sensors on the arm (International Journal of...
-
Researchers at Carnegie Mellon University developed an algorithm for estimating the sensor motion of a robotic arm by mounting a camera with inertia sensors on the arm. (The International Journal of...
-
At the intersection of Texas Avenue and University Drive, a yellow subcompact car with mass 950 kg traveling east on University collides with a red pickup truck with mass 1900 kg that is traveling...
-
1. During periods of bad weather, as compared with periods of clear weather, how many additional gallons of fuel, on the average, should FreeEx expect its planes to consume owing to airport...
-
The following is an excerpt from USAToday.com in July 2007: Microsoft (MSFT) on Thursday extended the warranty on its Xbox 360 video game console and said it will take a charge of more than $1...
-
State the form of the Laplace equation in axisymmetric spherical coordinates. Verify that the following functions satisfy this equation: \[r \cos \theta ; \quad \cos \theta / r^{2}\] A linear...
-
The comparative balance sheet for Mosaic Travel Services, Inc., for December 31, 2014 and 2013, is as follows: The following information is taken from the records of Mosaic Travel Services, Inc.: a....
-
The Field, Brown & Snow are partners and share income and losses equality. The partner decide to liquidate the partnership when their capital balances are as follows: Field, $131,100; Brown,...
-
Is it alright for non-native speaker of English to use a sound from his/her language as a substitute for an English sound that is nonexistent in his/her language? Why or why not? Explain your answer...
-
Company A buys 5,000 units of inventory for a total of $10,000 from an unrelated third- party company. Later, Company A sells these units to its subsidiary, Company B, for $15,000 in an intercompany...
-
You get a $400,000 mortgage to buy a condo. If rates are 3.5% and you will take a thirty year fixed loan, how much will your monthly payments be?
-
Suppose that for a financial institution, one-year rate sensitive assets (RSAs) are $240 million, and the one-year rate sensitive liabilities (RSLs) are $185 million. Total assets of the financial...
-
For each of the investment decisions below: (a) clearly define the following capital investment decisions, and (b) give an example for each one using any manufacturing industry or construction...
-
Summarize the purpose and current development of the following sustainability reporting framework or organizations and highlight their differences. 1. GRI (Global Reporting Initiative) 2. ISSB...
-
How can organizational leaders utilize transformative conflict resolution strategies to foster a culture of collaboration and innovation within complex multidisciplinary teams ?
-
If you no longer want to be long +700 gamma what would you try to do to dynamically hedge the gamma? a. sell an extra 700 shaes of the sp 500 index b. buy an extra 700 shaes of the sp 500 index c....
-
A 20-cm-square vertical plate is heated to a temperature of 30oC and submerged in glycerin at 10oC. Calculate the heat lost from both sides of the plate.
-
Approximately 50,000 new titles, including new editions, are published each year in the United States, giving rise to a $25 billion industry in 2001. In terms of percentage of sales, this industry...
-
When you think of political persuasion, you may think of the effortsthat political campaigns undertake to persuade you that their candidate is betterthan the other candidate. In truth, campaigns are...
-
In late 2013, the taxi company Yourcabs.com in Bangalore, India, was facing a problem with the drivers using their platformnot all drivers were showing up for their scheduled calls. Drivers would...
Study smarter with the SolutionInn App