Integer to BCD

Help Contents

Introduction

These functions convert from integer values to BCD:

Function NameDescription
SINT_TO_BCD_BYTEConvert a small integer (SINT) to two BCD digits encoded in a BYTE.
INT_TO_BCD_WORDConvert an integer (INT) to four BCD digits encoded in a WORD.
DINT_TO_BCD_DWORDConvert a double integer (DINT) to eight BCD digits encoded in a DWORD.
LINT_TO_BCD_LWORDConvert a long integer (LINT) to sixteen BCD digits encoded in a LWORD.

Examples

  1. Convert 69 in binary to BCD:
    SINT_TO_BCD_BYTE( 69 )

    The function call returns 16#69. The bit pattern 0100 0101 is converted to 0110 1001.

  2. Convert 4096 in binary to BCD:
    INT_TO_BCD_BYTE( 1000 )

    The function call returns 16#1000. The bit pattern 0000 0011 1110 1000 is converted to 0001 0000 0000 0000.

Standards Compliance

IEC 61131-3 Second Edition: Table 22.4.

IEC 61131-3 Third Edition: Table 22.4.

Further Information

Binary Coded Decimal (BCD) to Integer

To learn about converting BCD to Integers.

Conversion Functions

To learn about other conversion functions.

Glossary

For the meaning of terms used in Fernhill SCADA.