aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-06-15 14:38:02 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-06-15 14:38:02 +0200
commitbabcc00dcd189058433100417d6568a15fe62cf1 (patch)
tree5e014c402453ba380a3ed297defaf1695483e460 /global-functions
parent4cc8a0e1603082598b759344f85ab98d05d9ae27 (diff)
global-functions: introduce $HexToNum
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions16
1 files changed, 16 insertions, 0 deletions
diff --git a/global-functions b/global-functions
index 7a6d77a..d4aa574 100644
--- a/global-functions
+++ b/global-functions
@@ -30,6 +30,7 @@
:global GetMacVendor;
:global GetRandom20CharHex;
:global GetRandomNumber;
+:global HexToNum;
:global IfThenElse;
:global IPCalc;
:global LogPrintExit;
@@ -425,6 +426,21 @@
:return ([ :tonum [ :pick $Num 0 18 ] ] % $Max);
}
+# convert from hex (string) to num
+:set HexToNum do={
+ :local Input [ :tostr $1 ];
+ :local Hex "0123456789abcdef";
+ :local Multi 1;
+ :local Return 0;
+
+ :for I from=([ :len $Input ] - 1) to=0 do={
+ :set Return ($Return + ([ :find $Hex [ :pick $Input $I ] ] * $Multi));
+ :set Multi ($Multi * 16);
+ }
+
+ :return $Return;
+}
+
# mimic conditional/ternary operator (condition ? consequent : alternative)
:set IfThenElse do={
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={