2-225
2 Instruction Descriptions
NJ-series Instructions Reference Manual (W502)
BCD Conversion Instructions
2
BinToBCDs_**
The data type of data format number Format is enumerated type _eBCD_FORMAT. Select one of the
following: _BCD0, _BCD1, _BCD2, or _BCD3. The sign specification in the upper four bits of Out
depends on the BCD format number. The data format examples shown below use WORD data for Out.
The same sizes of data types are used for In and Out. The valid ranges depend on the value of Format,
as shown below.
The following example shows the BinToBCDs_WORD instruction when In is INT#−3452 and Format is
_BCD1.
Value of Format
_BCD0 _BCD1 _BCD2 _BCD3
Data
type of
In
↓
Data
type of
Out
SINT
↓
BYTE
−9 to 9 −79 to 79 −9 to 99 −19 to 99
INT
↓
WORD
−999 to 999 −7999 to 7999 −999 to 9999 −1999 to 9999
DINT
↓
DWORD
−9999999 to 9999999
−79999999 to
79999999
−9999999 to 99999999
−19999999 to
99999999
LINT
↓
LWORD
−999999999999999 to
999999999999999
−7999999999999999 to
7999999999999999
−999999999999999 to
9999999999999999
−1999999999999999 to
9999999999999999
Format = _BCD0
Valid range of Out: −999 to 999 (BCD)
3 BCD digits (12 bits)
3 BCD digits (12 bits) 3 BCD digits (12 bits)
#0 to #9: BCD digit 4 (positive)
#A: Negative, BCD digit 4 is 1
#F: Negative, BCD digit 4 is 0
(#B to #E: error)
#0 to #9: BCD digit 4 (positive)
#F: Negative
(#A to #E: error)
3 BCD digits (12 bits)
BCD digit 4 (three bits: 12 to 14)
Sign bit
Sign bit
0: Positive
1: Negative
0: Positive
1: Negative
Format = _BCD2
Valid range of Out: −999 to 9999 (BCD)
Format = _BCD3
Valid range of Out: −1999 to 9999 (BCD)
Format = _BCD1
Valid range of Out: −7999 to 7999 (BCD)
Out
15 1211 8 7 4 3 0
15 1211 8 7 4 3 0
15 1211 8 7 4 3 0
Out
Out
Out
15 1211 8 7 4 3 0
abc:=BinToBCDs_WORD(INT#-3452,_BCD1);
LD ST
abc
INT#-3452
_BCD1
BinToBCDs_WORD
EN ENO
In
Format
WORD BCD data INT data
2#1011_0100_0101_0010
INT#-3452
In
Out=abc