Logical Shift VariablePerforms a logical shift on the value in a variable and returns the result.
| Device Compatibility
|
Logical Shift is the number of bits to shift. A positive Logical Shift value shifts Var 1 to the left and a negative value shifts Var 1 to the right. The shift range is -31 through +31 bits. | |||||||
Var 1 is the variable holding the value to shift. Valid inputs are variables (0x01 through 0x78) and indirect variables (0x81 through 0xF8). | |||||||
Board ID is a unique number assigned by Measurement & Automation Explorer (MAX) used to send and receive commands and data to or from a specific NI motion controller. | |||||||
Ret Vect indicates the destination for the return data generated by this VI. Available return vectors include return data to the host (0xFF), return data to a variable (0x01 through 0x78), return data to an indirect variable (0x81 through 0xF8), and do not return data (0). Refer to Input and Return Vectors for more detailed information. | |||||||
error in (no error) describes error conditions that occur before this VI runs. The default input of this cluster is no error. If an error already occurred, this VI returns the value of error in in error out. The VI runs normally only if no incoming error exists. Otherwise, the VI passes the error in value to error out. The error in cluster contains the following parameters:
|
|||||||
Bd ID Out is provided for flow control. You can string together NI-Motion VIs by wiring the Bd ID Out terminal of one VI to the Board ID terminal of the next VI. | |||||||
error out contains error information. If error in indicates an error, error out contains the same error information. Otherwise, it describes the error status that this VI produces.
|
Using This VI
The Logical Shift Variable VI performs a logical shift on the value in the selected variable and returns the result to the destination specified by the Ret Vect.
For positive Logical Shift values:
V1 « Logical Shift = Result
For negative Logical Shift values:
V1 » Logical Shift = Result
where:
V1 is the value at Var 1.
Result is stored in the location pointed to by Ret Vect.
The result can be returned to a new variable or to the input variable, returned to the host computer or thrown away. In all cases the condition codes are set according to the resulting value, GREATER THAN, LESS THAN, or EQUAL to zero.
This VI actually performs an arithmetic rather than logical shift if the variable is a signed 32-bit value (i32). Negative values are sign-extended when shifted to the right. You can use this VI to perform division or scaling of signed or unsigned numbers. In this case the VI effectively performs the following:
V1 × 2(Logical Shift) = Result
Example 1
If the value in Var 1 is 0x0000 F002 and Logical Shift = –1, this VI returns 0x00007801.
Example 2
If the value in Var 1 is 0xFFFF F002 and Logical Shift = –1, this VI returns 0xFFFFF801. The sign of the value is preserved by sign-extension.
Note If you are doing onboard programming and are using Retn Vect to write data, this VI writes the variables starting at the memory address pointed to by Retn Vect in the following order: Var 1, Logical Shift. |
V1 / V2 = Result
The result can be returned to a new variable or one of the two input variables, returned to the host computer or thrown away. In all cases the condition codes are set according to the resulting value. The resulting value is compared to zero, and the appropriate condition code is set: GREATER THAN, LESS THAN, or EQUAL to zero.