Navigation:  Equipments (Devices) > SCA06 > Ladder > Data Transfer >

SWAP

Previous pageReturn to chapter overviewNext page

Block that performs a swap between the odd bytes and consecutive even bytes into Value and sends the value to Result.

 

Ladder Representation

 

SWAP_block

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

EN

BOOL

Block enabling

Value

WORD

DWORD

Input variable to be swapped

VAR_OUTPUT

ENO

BOOL

End of operation

Result

WORD UINT INT DWORD UDINT DINT REAL(*)

Output value

 

Operation

 

When this block has a TRUE value in EN, it changes the values of the odd bytes (1, 3, 5 and 7) and the consecutive even bytes (2, 4, 6 and 8, respectively) of the Value variable, storing the result in Result.

 

When EN has FALSE value, Result remains unchanged.

 

The ENO value forwards to the next Ladder block the EN value after the operation is completed.

 

wpshelp_common_fig_note

NOTA!

Caution when using in Result a variable of REAL type, because the block does not perform type conversion, that is, it only reverses the bytes in memory.

 

Block Flowchart

 

SWAP_flowchart

 

Example in Ladder

 

SWAP_example01

 

The example changes the position of byte 1 value of VALUE (0x44) with byte 2 of VALUE (0x3D), storing the final result (0x44_3D) in RESULT. The block ends with success and ENO output is activated.

 

SWAP_example02

 

The example changes the position of byte 1 value of VALUE (0x96) with byte 2 of VALUE (0xA8) and byte 3 of VALUE (0x0D) with byte 4 of VALUE (0x00), storing the final result (0x0D_00_96_A8) in RESULT. The block ends with success and ENO output is activated.

 

Example in ST

 

 The example below displays the instructions for applying the example above in the ST language.

 

 

VAR

  VALUE : DWORD := 16#3d44;

   RESULT : DINT;

END_VAR

 

RESULT := FB_SWAP(EN:=DI1, Value:=VALUE, ENO=>DO1);