From b59fad842b46464a001086b172953e747be89555 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 10 Sep 2023 10:25:51 +0200 Subject: [PATCH] reworked the decimal to hexadecimal converter. It now works. Thanks to @ATK for pointing out it was broken --- client/lualibs/utils.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/client/lualibs/utils.lua b/client/lualibs/utils.lua index 00103d6b4..03862ac29 100644 --- a/client/lualibs/utils.lua +++ b/client/lualibs/utils.lua @@ -262,14 +262,19 @@ local Utils = -- -- Converts DECIMAL to HEX - ConvertDecToHex = function(IN) - local B,K,OUT,I,D = 16, "0123456789ABCDEF", "", 0 - while IN > 0 do - I = I+1 - IN, D = math.floor(IN/B), math.modf(IN, B) + 1 - OUT = string.sub(K, D, D)..OUT + ConvertDecToHex = function(decimal) + if decimal == 0 then + return "0" end - return OUT + + local B,DIGITS,hex = 16, "0123456789ABCDEF", "" + + while decimal > 0 do + local remainder = math.fmod(decimal, B) + hex = string.sub(DIGITS, remainder + 1, remainder + 1) .. hex + decimal = math.floor(decimal / B) + end + return hex end, --- -- Convert Byte array to string of hex