How do you convert a "BCD"-type variable into an "INTEGER", and vice versa, in S7-SCL?
You can use the two data type conversion functions Class B - "BCD_TO_INT" and "INT_TO_BCD" - of S7-SCL to convert values of variables of the "BCD" type to "INTEGER" and vice versa. The integer value range must be between -999 and +999. The result is undefined outside the value range.
Fig. 01 shows an example of the two conversion functions in S7-SCL.
The value of the input variable "Int_In" of the INT data type is converted by the "INT_TO_BCD" function into a BCD-coded value of the WORD data type and output at the output parameter "Bcd_Out". The "BCD_TO_INT" function converts the value of the input variable "Bcd_In" of the WORD data type (BCD-coded value) into the INT data type. The integer value is transferred to the output parameter "Int_Out".
More information is available in the S7-SCL Online Help under "Conversion functions Class B".
The picture in this FAQ was created with S7-SCL version V5.3 + SP5.
The BCD representation of integers through the conversion functions described above is supported only as from S7-SCL version V5.3 + SP1. For BCD-INT conversion in earlier versions of S7-SCL, we recommend programming with the "BTI" and "ITB" functions in STL.
- You have a technical question / problem: Ask the Technical Support
- You want to discuss in our forum and exchange experiences with other users
- You want to create CAx data for one or more products
- You would like to send us feedback on this Entry