mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
global-functions: introduce $HexToNum
This commit is contained in:
@ -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={
|
||||
|
Reference in New Issue
Block a user