From 0734eac5df75080a943df188a9cb047eb937afb0 Mon Sep 17 00:00:00 2001 From: L4XB Date: Fri, 23 Oct 2026 06:07:31 +0200 Subject: [PATCH] fix: return 0x0 from decimal_to_hexadecimal(0) The loop builds no digit for 0, so the function returned '0x' while its docstring says the results match Python's hex(). --- conversions/decimal_to_hexadecimal.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conversions/decimal_to_hexadecimal.py b/conversions/decimal_to_hexadecimal.py index ee79592de5ca..9219ec3b097d 100644 --- a/conversions/decimal_to_hexadecimal.py +++ b/conversions/decimal_to_hexadecimal.py @@ -25,6 +25,8 @@ def decimal_to_hexadecimal(decimal: float) -> str: """ take integer decimal value, return hexadecimal representation as str beginning with 0x + >>> decimal_to_hexadecimal(0) + '0x0' >>> decimal_to_hexadecimal(5) '0x5' >>> decimal_to_hexadecimal(15) @@ -68,7 +70,7 @@ def decimal_to_hexadecimal(decimal: float) -> str: while decimal > 0: decimal, remainder = divmod(decimal, 16) hexadecimal = values[remainder] + hexadecimal - hexadecimal = "0x" + hexadecimal + hexadecimal = "0x" + (hexadecimal or "0") if negative: hexadecimal = "-" + hexadecimal return hexadecimal