BIT. - Work with Bits

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > BIT. - Work with Bits >

BIT. - Work with Bits

BIT.ToVal - change Parameter to Value-Format

Previous Top Next


MiniRobotLanguage (MRL)

 

BIT.ToVal - Convert Parameter from "Binary" to "Value"

Convert Parameter to "Value"

 

 

Intention

 

Generally there are two types od Parameters, these are "as value" and "as binary".

 

Whatever you want to do with BITs, generally there are two ways to specify Parameters for the Bit-Operations.

You can specify a number "16" as "Text" then it has two Bytes length. Byte 1 is "1" and the second Byte is "6" - we call this "by value".

You can also use the ASC-Code "16" and then only use 1 Byte to store the number. We call this "as binary".

More explanation is below under Remarks and see ! Smart Package Robot 's BIT. - Operations

 

The parameters P1 is the "Input" and it is "as Value".

The result is in P2 which is the "as binary" of P1.

 

VAN.$$LEA=2

CAL.$$P01=1+4+16+64+256+1024+4096+16384

BIT.ToBin|$$P01|$$P01|$$LEA

BIT.ToVal|b$$P01|$$P01|$$LEA

BIT.Show|v$$P01|$$ERG|$$LEA

MBX.The result can not directly displayed, but is:$crlf$$$ERG

ENR.

 

 

BIT_ToVal

 

 

 

Syntax

 

BIT.ToVal|[b/v]P1|P2[|P3]

 

 

 

Parameter Explanation

 

P1 - Variable containing a value or binary number. For example take the Number "9". It can be an ASC-Code "9" or the numeric number "9".

    You can define this with a prefix of "v" for value and "b" for "binary". If the prefix is omitted, "v" is the default setting for P1.

 

P2  - Variable for result or"-". If P2 is not a variable, the result is placed on the TOS.

 

P3 - optional, can be 1,2 or 4. Number of Bytes that are used internally. The number of Bits is the number of Bytes times 8.

    1 - 8 Bits

    2 - 16 Bits

    4 - 32 Bits

   

    Do not use the "8" Option. See Limitations below.

 

 

Example

 

'*****************************************************

' EXAMPLE 1:

'*****************************************************

VAN.$$LEA=2

CAL.$$P01=1+4+16+64+256+1024+4096+16384

BIT.ToBin|$$P01|$$P01|$$LEA

BIT.ToVal|b$$P01|$$P01|$$LEA

BIT.Show|v$$P01|$$ERG|$$LEA

MBX.The result can not directly displayed, but is:$crlf$$$ERG

ENR.

 

 

 

Remarks

Whatever you want to do with BITs, generally there are two ways to specify Parameters for the Bit-Operations.

You can specify a number "16" as "Text" then it has two Bytes length. Byte 1 is "1" and the second Byte is "6" - we call this "by value".

You can also use the ASC-Code "16" and then only use 1 Byte to store the number. We call this "as binary".

 

1. Specify Parameter as VALUE

 

' To specify the Parameter "as VALUE" we can just write it as a number, using the VAN.-Command.

' 9 is 1001 in Binary

VAN.$$P01=9

' We want extract Bit "1" which is "1" in Result

VAN.$$P02=1

BIT.Get|v$$P01|$$P02|$$RES

' We change the Result to a readable Value using the ASC.-Command. This will only work with 8-bit results

' The result will be "1" as CHR-value (Binary). To make it readable we use the ASC.-Command

ASC.$$RES|$$ERG

MBX.Result is $$ERG

 

This will give the result: "1", because the first bit in "1001" (dez. 9) is a "1".

In both cases, we did not specify P4 (Size-Parameter) so the default size of 8-bit was used.

 

2. Specify Parameter as BINARY

 

' To specify the Parameter "as Binary" we use the CHR. Command if the Parameter is just 8 bit (default).

' 9 is 1001 in Binary

CHR.9|$$P01

' We want extract Bit "1" which is "1" in Result

VAN.$$P02=1

BIT.Get|b$$P01|$$P02|$$RES

' We change the Result to a readable Value using the ASC.-Command. This will only work with 8-bit results

' The result will be "1" as CHR-value (Binary). To make it readable we use the ASC.-Command

ASC.$$RES|$$ERG

MBX.Result is $$ERG

 

3. Specify multi-Byte Parameters "as Binary" or "as Value"

 

' Use the "ToBin" or the "ToVal" Option to convert the Parameters

VAN.$$P01=9

' $$P02 will contain the result

BIT.ToBin|$$P01|$$P02|2

' $$P02 will contain the result

BIT.ToVal|$$P01|$$P02|2

 

 

Limitations:

 When using the "|8" Parameter, the lower 4 bits are possibly wrong. This is not a bug its due to the way variables are stored internally.

 Therefore we recommend to not use this option.

 

 

See also:

 

3.5 Hexadezimal, Decimal and Binary and more

VTH. - Variable to Hexadecimal

VDC. - Variable Decrement

CAL. - mathematical CALculation

VAR. - Variable Set Value/Clear

VAN. - Variable Numeric

! Smart Package Robot 's BIT. - Operations

BIT.16to8 - Split 1 Word into 2 Bytes

BIT.16to32 - concatenate 2 Words to 32 Bit DWord

BIT.32to16 - Split 1 DWord into 2 Words

BIT.8to16 - concatenate 2 Bytes to 16 Bit Word

BIT.AND - Use logical AND with Bits

BIT.Clear - Set Bit to 0

BIT.LShift - Shift Bits to Left, insert 0

BIT.NOT - Use logical NOT with Bits

BIT.OR - Use logical OR with Bits

BIT.RotateLeft - Rotate Bits Left

BIT.RotateRight - Rotate Bits Right

BIT.RShift - Shift Bits to Right, insert 0

BIT.Set - Set Bit to 1

BIT.Show - Show Bits in Binary-Numbers

BIT.Store - Set Bit to 1 or 0

BIT.ToBin - change Parameter to Binary-Format

BIT.Toggle - Switch Bit

BIT.ToVal - change Parameter to Value-Format

BIT.XOR - Use logical XOR with Bits

BIT.Get - check if Bit is set

  VDC. - Variable Decrement

  CAL. - mathematical CALculation

  VAR. - Variable Set Value/Clear

  VAN. - Variable Numeric