Convert binary numbers to hexadecimal numbers :param n: binary number :param visualize: Visualise the process :return: hexadecimal number
(n, visualize=False)
| 81 | |
| 82 | |
| 83 | def to_base16(n, visualize=False): |
| 84 | """ |
| 85 | Convert binary numbers to hexadecimal numbers |
| 86 | |
| 87 | :param n: binary number |
| 88 | :param visualize: Visualise the process |
| 89 | :return: hexadecimal number |
| 90 | """ |
| 91 | grouped_list = __create_group_list(n) |
| 92 | _list = [] |
| 93 | for value in grouped_list: |
| 94 | if visualize: |
| 95 | print("{} -> {}".format(value, BINARY_HEX_VALUES[value])) |
| 96 | # for each value in the grouped_list, |
| 97 | # get its respective value from the hex |
| 98 | # table by referencing the key with the |
| 99 | # current value from the grouped_list |
| 100 | _list.append(BINARY_HEX_VALUES[value]) |
| 101 | |
| 102 | return ''.join(_list) |
| 103 | |
| 104 | |
| 105 | def __create_group_list(n): |
nothing calls this directly
no test coverage detected