sint_to_bcd/int/dint (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The "xxx_to_bcd function" operates on the SINT, INT, and DINT data types. It will convert a value to its BCD representation.

 

 

Input:

in : DINT/INT/SINT

The binary value to convert.

Note that only a positive number can be converted.

 

Returns: DINT/INT/SINT

The resulting BCD-packed value.

 

Declaration:

 

FUNCTION dint_to_bcd : DINT;
VAR_INPUT
  in        : DINT;
END_VAR;
 
FUNCTION int_to_bcd : INT;
VAR_INPUT
  in        : INT;
END_VAR;
 
FUNCTION sint_to_bcd : SINT;
VAR_INPUT
  in        : SINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  a : INT;
  b : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  a := 1234;
  // Convert 1234 in binary to its BCD representation (16#1234)
  b := int_to_bcd(in:=a);
  // b is now 16#1234
  ...
END;
 
END_PROGRAM;