Convert to BCD (TO_BCD)
The Convert to BCD (TO_BCD) instruction converts a decimal value (0 Source 99,999,999) to a BCD value and stores the result in the Destination. BCD is the Binary Coded Decimal number system that expresses individual decimal digits (0-9) in a 4-bit binary notation.
Source | Destination | Destination Type |
---|---|---|
Negative source < 0 | 0 | |
Source > 9,999, 999,999, 999,999 | 16#9999_9999_9999_9999 | ULINT |
Source > 9,999, 999,999, 999,999 | 16#9999_9999_9999_9999 | LINT |
Source > 99,999,999 | 16#9999_9999 | UDINT |
Source > 99,999,999 | 16#9999_9999 | DINT |
Source > 99,999,999 | 16#9999 | UINT |
Source > 99,999,999 | 16#9999 | INT |
Source > 99,999,999 | 16#99 | USINT |
Source > 99,999,999 | 16#99 | SINT |
Available Languages
Ladder Diagram
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 conversions.
Ladder Diagram
Operand | Data Type | Format | Description |
---|---|---|---|
Source | SINT INT DINT LINT USINT UINT UDINT ULINT | Immediate tag | Value to convert to BCD |
Destination | SINT INT DINT LINT USINT UINT UDINT ULINT | tag | Tag to store the result |
Affects Math Status Flags
Conditional. See Math status flags.
Major/Minor Faults
A minor fault will occur if: | Fault type | Fault code |
---|---|---|
feature is enabled and overflow detected and Source < 0 | 4 | 4 |
feature is enabled and overflow detected and Source > 99,999,999 / 9,999, 999,999, 999,999 | 4 | 4 |
feature is enabled and overflow detected | 4 | 4 |
Execution
Ladder Diagram
Condition/State | Action Taken |
---|---|
Prescan | N/A. |
Rung-condition-in is false | N/A. |
Rung-condition-in is true | The controller converts the Source to BCD and places the result in the Destination. |
Postscan | N/A. |
Example
Ladder Diagram
Provide Feedback