mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-12-31 04:39:49 +08:00
reworked the decimal to hexadecimal converter. It now works. Thanks to @ATK for pointing out it was broken
This commit is contained in:
parent
cee33f7fe2
commit
b59fad842b
1 changed files with 12 additions and 7 deletions
|
@ -262,14 +262,19 @@ local Utils =
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Converts DECIMAL to HEX
|
-- Converts DECIMAL to HEX
|
||||||
ConvertDecToHex = function(IN)
|
ConvertDecToHex = function(decimal)
|
||||||
local B,K,OUT,I,D = 16, "0123456789ABCDEF", "", 0
|
if decimal == 0 then
|
||||||
while IN > 0 do
|
return "0"
|
||||||
I = I+1
|
|
||||||
IN, D = math.floor(IN/B), math.modf(IN, B) + 1
|
|
||||||
OUT = string.sub(K, D, D)..OUT
|
|
||||||
end
|
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,
|
end,
|
||||||
---
|
---
|
||||||
-- Convert Byte array to string of hex
|
-- Convert Byte array to string of hex
|
||||||
|
|
Loading…
Reference in a new issue