Skip to content

Commit 6b45f70

Browse files
Fix handling of zero in binary to hexadecimal conversion
1 parent 9f2a343 commit 6b45f70

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

conversions/binary_to_hexadecimal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def bin_to_hexadecimal(binary_str: str) -> str:
2929
raise ValueError("Non-binary value was passed to the function")
3030

3131
hex_str = "0x" + hex(int(binary_str, 2))[2:]
32+
if hex_str == "0x0":
33+
is_negative = False
3234
return "-" + hex_str if is_negative else hex_str
3335

3436

0 commit comments

Comments
 (0)