mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
global-functions: introduce $HexToNum
This commit is contained in:
parent
4cc8a0e160
commit
babcc00dcd
1 changed files with 16 additions and 0 deletions
|
@ -30,6 +30,7 @@
|
||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
:global GetRandom20CharHex;
|
:global GetRandom20CharHex;
|
||||||
:global GetRandomNumber;
|
:global GetRandomNumber;
|
||||||
|
:global HexToNum;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global IPCalc;
|
:global IPCalc;
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
|
@ -425,6 +426,21 @@
|
||||||
:return ([ :tonum [ :pick $Num 0 18 ] ] % $Max);
|
: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)
|
# mimic conditional/ternary operator (condition ? consequent : alternative)
|
||||||
:set IfThenElse do={
|
:set IfThenElse do={
|
||||||
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={
|
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={
|
||||||
|
|
Loading…
Reference in a new issue