<< Click to Display Table of Contents >> Navigation: 3. Script Language > Mathematical and algorithmic operations > Mathematical and algorithmic operations |
MiniRobotLanguage (MRL)
VTB. Command
Variable To Binary
Intention
Convert a numeric value into the Binary number-System, optional you can specify the length of the output string.
This very simple example
$$NUM=655345
VTB.$$NUM
DBP.$$NUM
Will give the result: "10011111111111110001"
In this example we say that we want the output to be formatted to 40 digits.
$$NUM=655345
VTB.$$NUM||40
DBP.$$NUM
ENR.
Therefore the result is "0000000000000000000010011111111111110001"
In both cases, we did not specify P2 (Target variable, therefore the result was placed in the source variable.
For details on how to prefix Hexadecimal, Octal or Binary numbers, see
3.5 Hexadezimal, Decimal and Binary and more
Syntax
VTB.P1[|P2][|P3]
Parameter Explanation
P1 - Variable containing any NUM
P2 - (optional) Variable for the result, if omitted result is been stored in Source variable.
P3 - (optional) optional, value that is used as a fix length of the output string.
Empty places are filled with "0"'s.
If you specify less digits then needed, the number will be clipped from the right side,
Example:
$$NUM=655345
VTB.$$NUM|$$TAR|2
will give you "01" as result (instead of 10011111111111110001)
Example
'*****************************************************
' EXAMPLE 1:
'*****************************************************
' Binary to hexadecimal
$$NUM=&B10011111111111110001
VTH.$$NUM
DBP.$$NUM
' Hexadecimal to decimal (unsigned)
$$NUM=&H0$$NUM
VTN.$$NUM|$$TAR|6
DBP.$$TAR
ENR.
Remarks
-
Limitations:
-
See also:
• 3.5 Hexadezimal, Decimal and Binary and more
• VTH. - Variable to Hexadecimal
• CAL. - mathematical CALculation
• VAR. - Variable Set Value/Clear