2 Instruction Descriptions
2-368
NJ-series Instructions Reference Manual (W502)
Swap
The Swap instruction swaps the upper byte and lower byte of a 16-bit value.
The Swap instruction swaps the upper byte and lower byte of data to convert In and assigns the result
to conversion result Out.
The following example is for when In is WORD#16#1234.
Instruction Name FB/FUN Graphic expression ST expression
Swap Swap Bytes FUN Out:=Swap(In);
Variables
Name Meaning I/O Description Valid range Unit Default
In Data to
convert
Input Data to convert Depends on data type.
--- 0
Out Conver-
sion result
Output Conversion result Depends on data type.
--- ---
Boolean
Bit strings Integers
Real
numbers
Times, durations,
dates, and text strings
BOOL
BYTE
WORD
DWORD
LWORD
USINT
UINT
UDINT
ULINT
SINT
INT
DINT
LINT
REAL
LREAL
TIME
DATE
TOD
DT
STRING
In OK
Out OK
Function
(@)Swap
EN ENO
In Out
abc:=Swap(WORD#16#1234);
LD ST
abc
WORD#16#1234
Swap
EN ENO
In
0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0
Bit
0
Bit
15
Bit
0
Bit
15
Lower byte
(bits 0 to 7)
Upper byte
(bits 8 to 15)
In
Out = abc