Skip to content

Commit

Permalink
reworked the decimal to hexadecimal converter. It now works. Thanks to
Browse files Browse the repository at this point in the history
…@atk for pointing out it was broken
  • Loading branch information
iceman1001 committed Sep 10, 2023
1 parent cee33f7 commit b59fad8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions client/lualibs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b59fad8

Please sign in to comment.