Question

IN PYTHON! Radix Conversion(*UP TO BASE 37*) Constraints: • Use only basic arithmetic and comparison operations....

IN PYTHON!

Radix Conversion(*UP TO BASE 37*)

Constraints:

• Use only basic arithmetic and comparison operations. Do not make any function calls other than the recursive call to convertBase

Write a recursive function: convertBase(n,base) that will convert the non-negative decimal number n (type integer) to the specified base and return it as a string. Note that decimal values can be converted to a different number base by repeatedly dividing the residual quotient of n // base until it is zero, then arranging the remainders in reverse. e.g., to convert 3510 to base 2:

35 // 2 ==> 17, remainder 1 ('1')

17 // 2 ==> 8, remainder 1 ('1')

8 // 2 ==> 4, remainder 0 ('0')

4 // 2 ==> 2, remainder 0 ('0')

2 // 2 ==> 1, remainder 0 ('0')

1 // 2 ==> 0, remainder 1 ('1')

3510 == 1000112

Number bases greater than 10 employ successive alphabetic letters to represent digit values greater than 9. For example, 1010 is represented using the letter 'A', 1110 is 'B' is, 1210 is 'C' and so on. e.g., 2710 converted to base 16:

27 // 16 ==> 1, remainder 11 ('B')

1 // 16 ==> 0, remainder 1 ('1')

2710 == 1B16

[Hint: use direct look-up on an alphabet string to convert the remainder "digit" to its character equivalent]

Example:

>>> convertBase(47,2) 101111

>>> convertBase(47,16) 2F

Here is what i have so far: I Just don't know how to change the remainder "digit" to an alphabet:

def convertBase(n,base):
add = n%base
if n<=1:
return str(n)
else:
return str(convertBase(n//base,base)) + str(add)

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
IN PYTHON! Radix Conversion(*UP TO BASE 37*) Constraints: • Use only basic arithmetic and comparison operations....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of num...

    In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of number can be anything such that all digits are represented using 0 to 9 and A to Z. Value of A is 10, Value for B is 11 and so on. So, write a program to convert a number to decimal Example: Input number is given as string and the output is an integer. Input Output Input...

  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

  • I am writing a class that can multiply and add very large values with hundreds and...

    I am writing a class that can multiply and add very large values with hundreds and thousands of digits in C++. Cannot add any more #includes Please implement with array of size 1000 2 3 4 // do not add more #includes. #include <string> #include <Cassert > #include <algorithm» 6 #include <vector» 7 #include <iostream> 8 9 using namespace std; 18 IIThe class LargeNumber is used to add and multiply large values up to hundreds of digits and/or more. 11...

  • /** * This program Performs various number base conversions. It also verifies if * a number...

    /** * This program Performs various number base conversions. It also verifies if * a number is valid in its base. * Author: M. Rahman * Date: 06 September 2018 */ public class NumberConversion { public static String dec2any(String dec, int base) { /** * Converts a decimal value to a target base * inputs: * dec: the decimal value to be converted * base: the target base * output: 256-base as dotted decimal, hex as usual, bases * over...

  • urgent Help needed in python program ! Thanx # This is a function definition. You can...

    urgent Help needed in python program ! Thanx # This is a function definition. You can ignore this for now. def parse_integer_list_from_string(string): """ Returns a list of integers from a string containing integers separated by spaces. """ # Split the line into a list of strings, each containing a number. number_string_list = string.split() # Create an empty list to store the numbers as integers. numbers = [] # Convert each string to an integer and add it to the list...

  • *In JAVA please* Tasks This lab has two parts: Write a recursive method that converts a...

    *In JAVA please* Tasks This lab has two parts: Write a recursive method that converts a decimal number to a different base number system. Print out the results after testing your method on a few different inputs. Task 1 – Recursive Method Create a recursive method that returns a given number converted from base ten to a given other base number system ranging from two to thirty-six. A decimal number, or base ten number, can be expressed in any other...

  • IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us...

    IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...

  • Output Enter base: 2 supply a list of digits separated by space: 1 0 0 1...

    Output Enter base: 2 supply a list of digits separated by space: 1 0 0 1 The value for Base = 2 and digits = 1 0 0 1 is 9 Enter base: 16 supply a list of digits separated by space: 99 All digits must be in the range [0,n) Enter base: 16 supply a list of digits separated by space: 9 9 The value for Base = 16 and digits = 9 9 is 153 Enter base: 2...

  • please add comments and make the progrom work with negative and simple as much as possible...

    please add comments and make the progrom work with negative and simple as much as possible Write a C program utilizing printf and scanf (do not use cout or cin) that does the following: 0. Using the division algorithm introduced in class to convert between base 10 and any other number base: 1. Prompts the user to enter an unsigned integer in base 10 (decimal) from the keyboard. 2. Prompts the user a new base ( greater than or equal...

  • Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all...

    Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...

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