. Answer must

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter6: Using Arrays
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

23. Answer must code. 

 

1
2 Integer base conversion algorithm
3
4 int_to_base(5, 2) return '101'.
5 base_to_int('F', 16) return 15.
6
7
8
9
11 T
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
11 11 11
import string
def int_to_base(num, base):
|| || ||
:type num: int
:type base: int
:rtype: str
is_negative = False
if num == 0:
return '0'
if num < 0:
is_negative = True
num *= -1
digit = string.digits + string.ascii_uppercase
res =
while num > 0:
11
res += digit [num % base]
num //= base
if is negative:
111111
return '-' + res[::-1]
return res[::-1]
def base_to_int (str_to_convert, base):
Note: You can use int() built-in function instead of this.
:type str_to_convert: str
:type base: int
:rtype: int
digit = {}
for ind, char in
digit [char]
multiplier = 1
res = 0
for char in str_to_convert[::-1]:
res +=
digit[char] * multiplier
multiplier *= base
return res
enumerate(string.digits+string.ascii_uppercase):
= ind
Transcribed Image Text:1 2 Integer base conversion algorithm 3 4 int_to_base(5, 2) return '101'. 5 base_to_int('F', 16) return 15. 6 7 8 9 11 T 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 11 11 11 import string def int_to_base(num, base): || || || :type num: int :type base: int :rtype: str is_negative = False if num == 0: return '0' if num < 0: is_negative = True num *= -1 digit = string.digits + string.ascii_uppercase res = while num > 0: 11 res += digit [num % base] num //= base if is negative: 111111 return '-' + res[::-1] return res[::-1] def base_to_int (str_to_convert, base): Note: You can use int() built-in function instead of this. :type str_to_convert: str :type base: int :rtype: int digit = {} for ind, char in digit [char] multiplier = 1 res = 0 for char in str_to_convert[::-1]: res += digit[char] * multiplier multiplier *= base return res enumerate(string.digits+string.ascii_uppercase): = ind
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
LUP Decomposition
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning