Question

In: Computer Science

Is there anyway I could get an example to set this python function set up? any...

Is there anyway I could get an example to set this python function set up? any help would be amazing.

basetonum (S, B) --- int:

  1. This function accepts as input a string S and a base B (int) where S represents a number in base B where B is between 2 and 10 inclusive. It should then return an integer in base 10 representing the same number as S. It should output 0 when S is the empty string. This function is the inverse of the previous function numtobase().

  2. Parameters: S (string), B (int)

  3. Returns : integer

  4. The function displays nothing.

  5. Steps to convert any base system to decimal:

    Step 1 − Determine the column (positional) value of each digit (this depends on the position of the digit and the base of the number system).
    Step 2 − Multiply the obtained column values (in Step 1) by the digits in the corresponding columns.

    Step 3 − Sum the products calculated in Step 2. The total is the equivalent value in decimal.

    Example with S = '11101' and B = 2 Binary Number − 11101 Calculating Decimal Equivalent −

    Nb43210 Step 1 11101 (1×2) + (1×2) + (1×2) + (0×2) + (1×2)

    Step2 11101 16+8+4+0+1 Step 3 11101 29

       

Binary Number − 11101 = Decimal Number – 29

Again, the key is to ask yourself... what has to change in order to output base B instead of base 2?

In [1]: basetonum('11101', 2) Out[1]: 29

In [2]: basetonum('', 4) Out[2]: 0

Solutions

Expert Solution

Below given the python solution and the sample output to convert any base system to decimal.

val(c) and basetonum(S,B) are the two functions used in the program to convert any base system to decimal.


Related Solutions

I need the code in python where I can encrypt and decrypt any plaintext. For example,...
I need the code in python where I can encrypt and decrypt any plaintext. For example, the plaintext "hello" from each of these Block Cipher modes of Operation. Electronic Code Block Mode (ECB) Cipher block Mode (CBC) Cipher Feedback Mode (CFB) Output feedback Mode (OFB) Counter Mode (CTR) Here is an example, Affine cipher expressed in C. Encryption: char cipher(unsigned char block, char key) { return (key+11*block) } Decryption: char invcipher(unsigned char block, char key) { return (163*(block-key+256)) }
How to set up experimental design for 3 factors at 4 different levels. I get in...
How to set up experimental design for 3 factors at 4 different levels. I get in total I should end up with 81 experimental runs. Can you help me to determine how to distribute these 4 levels across 3 factors?
Could I please get an explicit example of a conformal transformation represented through only rotations on...
Could I please get an explicit example of a conformal transformation represented through only rotations on the riemann sphere to help show mobius transformations?
Please fix this python script, I keep getting a return outside function error and cannot get...
Please fix this python script, I keep getting a return outside function error and cannot get it to run: def caesar(plainText, shift):     cipherText = "" for char in plainText:     newChar = ord(char) + shift     if newChar > 128:       newChar = newChar % 128     finalChar = chr(newChar)     cipherText += finalChar return cipherText text = input("Enter a message: "); s = input("Enter the distance value: "); print (caesar(text, int(s)));
Could I please get explainations and working out as to how to get to the answers....
Could I please get explainations and working out as to how to get to the answers. Note that  is where part of the answer goes. 1. Consider the following ArrayList list: ArrayList list = new ArrayList(Arrays.asList(10,70,20,90)); //list = [10, 70, 20, 90] Complete the following statements so that list contains the items [50, 70, 20] Do NOT include spaces in your answers. list.remove(  ); list.  (  , 50); 2. Assume there exists an ArrayList list that...
I was wondering if I could get a step by step process to answer this question?
I was wondering if I could get a step by step process to answer this question?
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values in the dictionary. For example: dict1 = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':4}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} dict2 = {300:{'s': 300}, 400:{'s': 100, 'g': 100, 'p': 100}, 500: {'s': 50 ,'m': 400, 'p':30, 'i': 50}, 600: {'s': 40, 'i': 400}, 700: {'m': 100, 'p': 50}} def dict_sum(db): should give output...
1. "Give an example of a function that is defined on the set of integers that...
1. "Give an example of a function that is defined on the set of integers that is not a one-to-one function." Keep in mind that the above domain must be the set of integers. Identify what your codomain is, too. 2. "Give an example of a function that is defined on the set of rational numbers that is not an onto function." The above domain must be the set of rational numbers. Identify what your codomain is, too. This is...
Try to get in touch with any person you know( it could be your relative or...
Try to get in touch with any person you know( it could be your relative or friend) who undergone or undergoing a special diet. Describe what it is made of and for what specific condition it is. You may cite specific food items and other details pertinent to the diet.
I am stumped on these problems and homework question, please could I get the answers to...
I am stumped on these problems and homework question, please could I get the answers to the questions below from an expert. Thank you 5). Suppose that two population proportions are being compared to test weather there is any difference between them. Assume that the test statistic has been calculated to be z= 2.21. Find the p-value for this situation?   a). p-value = 0.4864 b). p-value = 0.0272 c). p-value = 0.9728 d). p-value = 0.0136. 8). If you are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT