flex_lshift_var

NI-Motion Functions

flex_lshift_var

Device Compatibility

Device Compatibility
7330
N
7340
Y
7344
Y
7350
Y
7390
N
NI SoftMotion Controller for CANopen—Xenus
N
NI SoftMotion Controller for CANopen—Accelnet
N

Logical Shift Variable

Usage

status = flex_lshift_var(u8 boardID, u8 variable1, i8 logicalShift, u8 returnVector);

Purpose

Performs a logical shift on the value in a variable and returns the result.

Parameters

Name Type Description
boardID u8 assigned by Measurement & Automation Explorer (MAX)
variable1 u8 variable holding the value to shift
logicalShift i8 number of bits to shift
returnVector u8 destination for the result

Parameter Discussion

variable1 is the variable holding the value to shift. Valid inputs are variables (0x01 through 0x78) and indirect variables (0x81 through 0xF8).

logicalShift is the number of bits to shift. A positive logicalShift value shifts variable1 to the left and a negative value shifts variable1 to the right. The shift range is –31 through +31 bits.

returnVector indicates the destination for the return data generated by this function. Available return vectors include return data to the host (0xFF), to a variable (0x01 through 0x78), to an indirect variable (0x81 through 0xF8), and return no data (0). Refer to Input and Return Vectors for more detailed information.

Using This Function

This function performs a logical shift on the value in the selected variable and returns the result to the destination specified by the returnVector.

For positive logicalShift values:

V1 « Logical Shift = Result

For negative logicalShift values:

V1 » Logical Shift = Result

where:
V1 is the value at variable1.
Result is stored in the location pointed to by returnVector.

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. This value is compared with 0, and the appropriate condition code is set: GREATER THAN, LESS THAN, or EQUAL to zero.

This function 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 function to perform division or scaling of signed or unsigned numbers. In this case the function effectively performs the following:

V1 × 2(Logical Shift) = Result

Example 1

If the value in variable1 is 0x0000 F002 and logicalShift = –1, this function returns 0x00007801.

Example 2

If the value in variable1 is 0xFFFF F002 and logicalShift = –1, this function returns 0xFFFFF801. The sign of the value is preserved by sign-extension.