# Integer to String¶

In [1]:
n = 769

print(n)
base = 10

print(n//base, n%base)
n = n//base

print(n//base, n%base)
n = n//base

print(n//base, n%base)
n = n//base

769
76 9
7 6
0 7

In [13]:
import string
from rcviz import CallGraph, viz

In [14]:
cg = CallGraph()

@viz(cg)
def to_str(n, base):
"""Convert from any base from 2 to 16"""

#convert_string = "0123456789ABCDEF"  # digits for hexadecimal values
convert_string = string.digits + string.ascii_uppercase[0:6]

if n < base:
return convert_string[n]
else:

In [4]:
to_str(769, 10)

Out[4]:
'769'
In [5]:
cg

callviz: Rendering in inline in Jupyter Notebook

Out[5]:
In [8]:
to_str(123456, 10)

Out[8]:
'123456'
In [9]:
cg

callviz: Rendering in inline in Jupyter Notebook

Out[9]:
In [15]:
to_str(123456, 2)

Out[15]:
'11110001001000000'
In [16]:
cg

callviz: Rendering in inline in Jupyter Notebook

Out[16]:
In [26]:
to_str(769, 2)

1

Out[26]:
'1100000001'
In [27]:
bin(769)

Out[27]:
'0b1100000001'
In [28]:
hex(769)

Out[28]:
'0x301'
In [29]:
oct(769)

Out[29]:
'0o1401'
In [30]:
x = 0x301

In [31]:
x

Out[31]:
769
In [32]:
to_str(769, 16)

3

Out[32]:
'301'
In [33]:
to_str(769, 8)

1

Out[33]:
'1401'
In [34]:
to_str(769, 7)

2

Out[34]:
'2146'