Attention
IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.
BCD_TO_INT / INT_TO_BCD¶
Convert between Binary-Coded Decimal (BCD) encoded bit strings and integer values.
IEC 61131-3 |
Section 2.5.1.5.1 |
Support |
Supported |
Signatures¶
BCD_TO_INT¶
# |
Input (IN) |
Return Type |
Support |
|---|---|---|---|
1 |
|
|
Supported |
2 |
|
|
Supported |
3 |
|
|
Supported |
4 |
|
|
Supported |
INT_TO_BCD¶
# |
Input (IN) |
Return Type |
Support |
|---|---|---|---|
1 |
|
|
Supported |
2 |
|
|
Supported |
3 |
|
|
Supported |
4 |
|
|
Supported |
Description¶
BCD (Binary-Coded Decimal) encodes each decimal digit in a 4-bit nibble.
For example, the decimal value 42 is encoded as 0100_0010 in BCD
(4 in the high nibble, 2 in the low nibble).
BCD_TO_INT decodes a BCD-encoded bit string into its integer value.
Invalid BCD nibbles (values 10–15) are treated as 0.
INT_TO_BCD encodes an integer value into BCD format. Values that
exceed the maximum representable BCD value for the target width wrap
around.
Maximum values per width:
BYTE: 99WORD: 9999DWORD: 99999999LWORD: 9999999999999999
Example¶
See Also¶
Type Conversions — other type conversion functions