mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
19 lines
307 B
Python
19 lines
307 B
Python
def convert_to_hex(num: int) -> str:
|
|
|
|
hex_chars = "0123456789abcdef"
|
|
size = 32
|
|
base = 16
|
|
|
|
if num == 0:
|
|
return "0"
|
|
|
|
if num < 1:
|
|
num += 2**size
|
|
|
|
result = ""
|
|
while num:
|
|
result += hex_chars[num % base]
|
|
num //= base
|
|
|
|
return result[::-1]
|