global-functions: $HexToNum: use :tonum

This commit is contained in:
Christian Hesse 2024-01-16 22:20:19 +01:00
parent be4221264c
commit 29623a46ea

View file

@ -488,16 +488,14 @@
# convert from hex (string) to num # convert from hex (string) to num
:set HexToNum do={ :set HexToNum do={
:local Input [ :tostr $1 ]; :local Input [ :tostr $1 ];
:local Hex "0123456789abcdef0123456789ABCDEF";
:local Multi 1;
:local Return 0;
:for I from=([ :len $Input ] - 1) to=0 do={ :global HexToNum;
:set Return ($Return + (([ :find $Hex [ :pick $Input $I ] ] % 16) * $Multi));
:set Multi ($Multi * 16); :if ([ :pick $Input 0 ] = "*") do={
:return [ $HexToNum [ :pick $Input 1 [ :len $Input ] ] ];
} }
:return $Return; :return [ :tonum ("0x" . $Input) ];
} }
# return human readable number # return human readable number