- Home
- Function/Function Block Reference
- IEC 61131-3 Functions and Function Blocks
- Data Type Conversion
- TO_UINT
TO_UINT
Type | Function | ||||||||||||||||||||||||||||||||||
Description | The overloaded function TO_UINT converts an input value of various data types into an output value of the data type UINT (see description of the input for the supported data types). | ||||||||||||||||||||||||||||||||||
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_UINT function, this applies to the USINT input data type. |
||||||||||||||||||||||||||||||||||
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.
If any of the listed string errors occurs, an error is written to the Online log in the MESSAGES window.
Note for large real values: Sample: 3.6000000E+7 => 3.600000E+7 => SINT: 0 3.6000001E+7 => 3.600000E+7 => SINT: 0 3.6000002E+7 => 3.600000E+7 => SINT: 0 3.6000003E+7 => 3.600004E+7 => SINT: 4 3.6000004E+7 => 3.600004E+7 => SINT: 4 ... The values 3.600001E+7, 3.600002E+7, 3.600003E+7 have no representation in REAL and will be set to the next possible REAL value. This results in gaps. The larger the number is, the larger the gap will be, until always 0 will be shown as result. |
||||||||||||||||||||||||||||||||||
Examples | ![]() out := TO_UINT(16#7F); (* results in 127 *) out := TO_UINT(16#FFFF); (* results in 65,535 *) out := TO_UINT(16#FFFF0000); (* results in 0 *) out := TO_UINT(DINT#65535); (* results in 65,535 *) out := TO_UINT(DINT#65536); (* results in 0 *) out := TO_UINT(SINT#-128); (* results in 128 *) out := TO_UINT(DINT#-65537); (* results in 65,535 *) out := TO_UINT(UDINT#65537); (* results in 1 *) out := TO_UINT(REAL#6.5535E+004); (* results in 65,535 *) out := TO_UINT(REAL#6.5536E+004); (* results in 0 *) out := TO_UINT('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, ENO is set to FALSE.
|