MCPcopy Index your code
hub / github.com/OmkarPathak/pygorithm / to_ascii

Function to_ascii

pygorithm/binary/base2.py:19–44  ·  view source on GitHub ↗

Convert binary to ASCII :param b: binary number or array :param visualize: Show process :return: ASCII String

(b, visualize=False)

Source from the content-addressed store, hash-verified

17
18
19def to_ascii(b, visualize=False):
20 """
21 Convert binary to ASCII
22
23 :param b: binary number or array
24 :param visualize: Show process
25 :return: ASCII String
26 """
27 binary = b
28 # Make sure give binary is a str array
29 if type(b) is str:
30 binary = b.split(' ')
31 elif type(b) is list:
32 binary = b
33
34 string = ''
35
36 for b_value in binary:
37 if visualize:
38 print("{} -> {} -> {}".format(
39 b_value, to_base10(int(b_value)),
40 chr(to_base10(int(b_value)))
41 ))
42 value = to_base10(int(b_value))
43 string += chr(value)
44 return string
45
46
47def to_base10(n, visualize=False):

Callers

nothing calls this directly

Calls 2

splitMethod · 0.80
to_base10Function · 0.70

Tested by

no test coverage detected