BCD Translation (BCD)
Binary-Coded Decimal (BCD) translation of a 4-bit value.
OUT =
(BCD(IP0, IP1, IP2, IP3) * M) + N

Parameter values for the BCD function:
Parameter | Data Type | Description |
---|---|---|
IP0 | BOOL | Input parameter with least significant bit |
IP1 | BOOL | Input parameter |
IP2 | BOOL | Input parameter |
IP3 | BOOL | Input parameter with most significant bit |
M | DINT | Value multiplier. This value must be a power of 10. |
N | DINT | Integer value added to the BCD conversion value, allowing the cascade of several
BCD functions. |
OUT | DINT | Resulting decimal digit. |
When N is -1, the function assumes that an up-stream conversion error occurs and
returns -1, causing all chained BCD functions to generate values of -1. Conversion errors
result from any of these conditions:
- IP0, IP1, IP2, or IP3 values representing an invalid BCD number
- M values which are not powers of 10
- Overflow conditions, where theERRSTATOverflow error counter increments
The value of OUT for each combination of IP0, IP1, IP2, and IP3 when N = 0 and M =
1:
IP3 | IP2 | IP1 | IP0 | OUT |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 |
0 | 0 | 1 | 0 | 2 |
0 | 0 | 1 | 1 | 3 |
0 | 1 | 0 | 0 | 4 |
0 | 1 | 0 | 1 | 5 |
0 | 1 | 1 | 0 | 6 |
0 | 1 | 1 | 1 | 7 |
1 | 0 | 0 | 0 | 8 |
1 | 0 | 0 | 1 | 9 |
1 | 0 | 1 | 0 | -1 (conversion error) |
1 | 0 | 1 | 1 | -1 (conversion error) |
1 | 1 | 0 | 0 | -1 (conversion error) |
1 | 1 | 0 | 1 | -1 (conversion error) |
1 | 1 | 1 | 0 | -1 (conversion error) |
1 | 1 | 1 | 1 | -1 (conversion error) |
Function Block Diagram Example

Structured Text Example
BCD_value := BCD(Val1, Val2, Val3, Val4, 10, 2);
Provide Feedback