1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Yakvenalex [24]
3 years ago
10

Function Name: d2x Parameters: int, int Returns: string Description: Write function, d2x, that takes as input a nonnegative inte

ger v (in the standard decimal representation) and an integer x between 2 and 9 and returns a string of digits that represents the base-x representation of v. To convert a value, v from base-10 to base-x, v is divided by x successively until the quotient of v divided by x is 0. On each successive division, the remainder is the new most significant digit in your answer. For the function call, d2x(10, 2), should return '1010':

Computers and Technology
1 answer:
Marina CMI [18]3 years ago
6 0

Answer:

I am writing a Python program. Let me know if you want the program in some other programming language.

#definition of function d2x which takes two parameters v: which is a non #negative integer and x which is an integer between 2 and 9. this method #returns string of digits that represents the base-x representation of v

def d2x(v,x):

   remainder = v%x  

   if v<=1:

       return str(v)

   else:

       return str(d2x(v//x,x)) + str(remainder)

 

v= int(input("Enter a non negative integer: "))

x= int(input("Enter an integer between 2 and 9: "))

print(d2x(v,x))

Explanation:

I will explain the code line by line.

def d2x(v,x) This is the definition of function d2x which takes two parameters v: which is a non negative integer and x which is an integer between 2 and 9. This method returns string of digits that represents the base-x representation of v.

Now lets take an example to understand the working of this function.

Suppose the value of v = 10 and x = 2.

remainder = v%x  takes the mod of v and x which returns the remainder of the division of v by x. So v%x = 10 % 2 = 0. So remainder = 0.

if v<=1 This if condition checks if the value of v is less than or equal to 1. This is false because v=10 and 10 is greater than 1. If v is 1 or less than return str(v)  will return the value of v as it is i.e. 10.

Since the IF condition is false so the else part will execute which has the following statement: return str(d2x(v//x,x)) + str(remainder)

This calls the d2x function recursively. Here v is divided by x successively until the quotient of v divided by x is 0. On each successive division, the remainder is the new most significant digit. In v//x, the double slash is called floor division or integer division which we use as both v and x are integers. So using recursion the above statement becomes:

str(d2x(v//x,x)) + str(remainder)

str(d2x(10//2,2) + str(0)

d2x(5,2) + (0)

Now d2x will again be called recursively to perform the division and this successive division continues until quotient of v divided by x is 0. Here str() method is used returns the result in the form of string.  So v%x is the number which is added to the end of resultant number. v//x is the recursive portion which keeps using the answer of the previous binary number. This means 10 in base 2 calls convert(5,2), then adds 0 at the end. So when v//x=5 and v%x=0 So the answer is 1010.

At the end v= int(input("Enter a non negative integer: "))

x= int(input("Enter an integer between 2 and 9: "))  these two statement wills take integer input from user and print(d2x(v,x)) calls d2x method and print the result.

You might be interested in
If an ARQ algorithm is running over a 40-km point-to-point fiber optic link then:
Dennis_Churaev [7]

Answer and Explanation:

Given data:

Distance (D) = 40 KM

Speed of light in the fiber =Distance/ speed of light in the fiber

a) Delay (P) = Distance/ speed of light in the fiber

= (40,000 Meters/2×108 m/s)

=( 40×103 Meters/2×108 m/s)

Propagation delay (P) = 0.0002 seconds or 200 microseconds

b)

if propagation delay is 0.0002 Seconds roundup trip time (RTT) will be 0.0004 Seconds or 400 micro Seconds

Essentially since transmission times and returning ACKs are insignificant all we really need is a value slightly greater than 0.0004 seconds for our timeout value.

c)

The obvious reasons would be if the data frame was lost, or if the ACK was lost. Other possibilities include extremely slow processing on the receive side (late ACK).

Or Extremely Slow Processing of the ACK after it is received back at the send side.

4 0
3 years ago
Which control program flow options runs to the end of the code block and resumes the break mode at the statement that follows?
Aliun [14]

Answer:

Step Out

Explanation:

In the field of computer science, the control flow or the flow of control is defined as the order where the individual statements, \text{function calls} or instructions of a program are \text{evaluated or executed. }

The Step Out control flow program runs to the \text{end of the code block} and it resumes the \text{break mode} at the statement that it follows.

5 0
3 years ago
I need help with this work
lisabon 2012 [21]

Answer:

B. Balanced depending and the type of questions

5 0
2 years ago
Creating a wedding website on the knot- how to make the text wide
Nady [450]

Answer:

go to the side with you mouse drag it ove or the restoere down button at the top right in between the - and the x hope this haelp may you mark me as brainlyest pls and thank you have a  bless day <3

Explanation:

3 0
2 years ago
Choose all statements that identify the benefits of programming design.
Lubov Fominskaja [6]

Answer:

yes

Explanation:

it provides a design approach to a specific type of problem

4 0
3 years ago
Read 2 more answers
Other questions:
  • Before responding to an e-mail from another student in an online course, a student should
    13·2 answers
  • Data cannot be sorted of filtered accurately if there are ________.
    10·2 answers
  • Julie bought a house for $315,000 and has a $285,000 mortgage. she claims she has $315,000 in equity. is she correct? if not, ho
    12·2 answers
  • A technology company only hires applicants who are under the age of 30. This company could face possibly _________ consequences
    9·2 answers
  • What is the output of the following program? #include using namespace std; class TestClass { private: int val; void showVal() {
    5·1 answer
  • Jabari is writing a program which prompts a user for a value with a decimal. Which function should he use? float() int() print()
    9·2 answers
  • If data from a DOS system is electronically sent to an EHR or other Windows-based system via an interface to populate an indexed
    7·1 answer
  • What is the best data structure to solve the following problem? a) A list needs to be built dynamically. b) Data must be easy to
    11·1 answer
  • 7.2 need help plzs 15 points
    13·1 answer
  • Sebutkan contoh komputer analog, komputer digital, dan komputer hybrid
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!