Swap Byte (SWPB)

The SWPB instruction rearranges the order of the bytes of the Source. It places the result in the Destination.
Available Languages
Ladder Diagram
Ladder Diagram_Swap Byte (SWPB)_v1
FactoryTalk Design Studio
DSL - Ladder Diagram
SWPB(Source, Order Mode, Dest);
Operands
IMPORTANT: Unexpected operation may occur if:
  • Output tag operands are overwritten
  • Members of a structure operand are overwritten
  • Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data Conversion.
Ladder Diagram
Operand
Data Type
Format
Description
Source
INT
DINT
tag
Tag that contains the bytes to rearrange.
Order Mode
list item
This operand specifies how to reorder. Refer Order Mode table.
Dest
INT
DINT
tag
Tag to store the bytes in a new order. Refer Dest table.
If selecting the HIGH/LOW order mode, enter it as HIGHLOW (without the slash).
Order Mode
If the Source is an
And you want to change the bytes to this pattern(each letter represents a different byte)
Then select
INT
AB => BA
Any option
DINT
ABCD => DCBA
REVERSE
ABCD =>CDAB
WORD
ABCD => BADC
HIGH/LOW
Dest
If the Source is an
Then the Destination must be an
INT
INT, DINT
If the destination is a DINT, the result is sign extended after bytes swap.
DINT
DINT
Affects Math Status Flags
No
Major/Minor Faults
None specific to this instruction. See Index through arrays for array-indexing faults.
Execution
Ladder Diagram
Condition/State
Action Taken
Prescan
N/A
Rung-condition-in is false
N/A
Rung-condition-in is true
The instruction rearranges the specified bytes.
Postscan
N/A
Examples
Example 1 - Swap the bytes of a DINT tag
The three SWPB instructions reorder the bytes of DINT_1 according to a different order mode. The display style is ASCII, and each character represents one byte. Every instruction places the bytes, in the new order, in a different Destination.
Ladder Diagram
FTStudio-SWPB-LD-EX1-V1
Example 2 - Swap the bytes in all elements of an array
Ladder Diagram
FTStudio-SWPB-LD-EX2_1-V1
FTStudio-SWPB-LD-EX2_2-V1
FTStudio-SWPB-LD-EX2_3-V1
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.