- Home
- Function/Function Block Reference
- IEC 61131-3 Functions and Function Blocks
- Data Type Conversion
- TO_DINT
TO_DINT
Type | Function | |||||||||||||||||||||||||||
Description | The overloaded function TO_DINT converts an input value of various data types into an output value of the data type DINT (see description of the input for the supported data types). A signed conversion is performed. | |||||||||||||||||||||||||||
Parameters | Input
![]()
![]()
|
|||||||||||||||||||||||||||
Conversion rules | ![]() The conversion is done by copying the input value bitwise to the output value, i.e., a binary transfer from the input data type to the output data type is performed.
![]() The data type conversion is done as follows:
Example:
![]() The type conversion is divided into two steps. First the floating point value is rounded to the next higher absolute integer according to standard rounding rules (for example, 2.5 is rounded to 3 and -2.5 is rounded to -3). In the second step the rounded input value is converted to the least significant bits of the output value. ![]()
For the TO_DINT function, this applies to INT, SINT, UINT and USINT input data types. |
|||||||||||||||||||||||||||
Error behavior | ![]() The following table shows the errors which may occur while executing the function and the value returned by the function in the corresponding error case. As described, the value returned by the function in the error case depends on the value of the input (for example, if the input value of data type REAL is not a legal number (NaN), the function returns the value 0).
|
|||||||||||||||||||||||||||
Examples | ![]() out := TO_DINT(16#7F); (* results in 127 *) out := TO_DINT(16#FFFF); (* results in -1 *) out := TO_DINT(16#FFFFFFFF00000000); (* results in 0 *) out := TO_DINT(16#FFFFFFFFFFFFFFFF); (* results in -1 *) out := TO_DINT(LINT#2147483647); (* results in 2,147,483,647 *) out := TO_DINT(LINT#-2147483648); (* results in -2,147,483,648 *) out := TO_DINT(LINT#4294967295); (* results in -1 *) out := TO_DINT(LINT#4294967299); (* results in 3 *) out := TO_DINT(LINT#4294967299); (* results in 3 *) out := TO_DINT(UDINT#4294967295); (* results in -1 *) out := TO_DINT(REAL#2.147483648E+9); (* results in -2,147,483,648 *) out := TO_DINT('123'); (* results in 123 *) |
|||||||||||||||||||||||||||
Additional information | ![]() The POU is only executed if TRUE is applied to the EN input. If EN = FALSE, the POU is not executed and ENO = FALSE indicates the inactivity. If any of the errors listed under "Error behavior" occurs while executing the function, the POU is not executed, the last valid value is kept on the output and ENO=FALSE.
|