Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 48711306, Entry date: 03/31/2016

In STEP 7 (TIA Portal), how do you convert the data types for the S7-1200/S7-1500?

  • Entry
  • Associated product(s)
In STEP 7 (TIA Portal), you can use the conversion functions from the "Instructions" palette to convert the contents of the variables to the selected data types for the S7-1200/S7-1500.

The table below (Fig. 1) gives you an overview of the most used conversions.

Fig. 1

Conversion of data types INT, DINT, REAL and BCD numbers
STEP 7 (TIA Portal) provides the operation "CONV" (convert) to convert the data types INT, DINT, REAL and BCD numbers. Follow the instructions below to insert and parameterize this operation in your block editor.
  1. In the block editor you open the "Instructions" palette and then the folder "Simple Instructions > Converters". Use drag-and-drop to insert the "CONVERT" instruction in your network.
  2. After inserting the instruction box, the instruction data types are still not defined and under "CONV" you still see the wildcard characters "??? to ???". When you move the cursor over the left triangle of the first three question marks, an arrow key is displayed.
  3. Click the left arrow key and from the drop-down menu that opens you select the desired data type for the input parameter "IN" (INT, for example).
  4. Repeat the procedure for the output parameter "OUT" and from the drop-down menu on the right you select the data type to which you wish to convert the number value (REAL, for example). In this example you can convert a number value of the data type INT into the data type REAL ("Int to Real").
    If you parameterize the input and output parameters directly with the variables, the instruction is defined automatically with the associated data types and Steps 2 to 4 above are not necessary.
  5. Parameterize the inputs and outputs of the converter with the variables of your choice. After parameterizing the inputs and outputs you can convert the number values below, for example.
  • From Int to Int, DInt, Real, Bcd16, USint, UInt, UDint, SInt, LReal and Char
  • From DInt to Int, DInt, Real, Bcd32, USint, UInt, UDint, SInt, LReal and Char
  • From Real to Int, DInt, Real, USint, UInt, UDint, SInt and LReal
  • From USint to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
  • From UInt to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
  • From UDint to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
  • From SInt to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
  • From LReal to Int, DInt, Real, USint, UInt, UDint, SInt and LReal
  • From Char to Int, DInt, USint, UInt, UDint, SInt and Char
  • From BCD16 (16-bit) to Int,
  • From BCD32 (32-bit) to DInt.

Notes on the CONVERT instruction
Fig. 2 shows an example of data conversion from the BCD format to Real and from Byte to SInt.

  • A number value in the BCD format must first be converted into the data type Int or DInt before you can convert it into the data type REAL, for example.
  • If you perform a data type conversion from Byte to SInt or from Byte to USInt, with the CONVERT instruction you must manually set the data type SInt or USInt at the input and output.

Further information is available in the STEP 7 (TIA Portal) Online Help and under CONVERT: Convert value.

Fig. 2

Rounding of REAL numbers
The instructions below are available for you to round a number value of the data type REAL to a whole number (INT or DINT). These instructions are in the "Converters" folder as described above.
  • "CEIL": Rounding up to the next whole number.
  • "FLOOR": Rounding down to the next whole number.
  • "ROUND": Rounding to the next whole number.
  • "TRUNC": No rounding.

Conversion of STRING data types
The table below contains instructions for converting the String data type. The procedure for programming this is identical to that described in the instructions.

Advanced Instructions

S_CONVConvert character string
STRG_VALConvert character string to number value
VAL_STRGConvert number value to character string
Strg_TO_CharConvert character string to array of CHAR
Char_TO_StrgConvert array of CHAR to character string
ATHConvert ASCII character string to hexadecimal number
HTAConvert hexadecimal number into ASCII character string

Conversion to the TIME data format
Using the advanced instruction "T_CONV" you convert a numerical value of the INT data type into a time stamp (TIME) and vice versa. You must convert all other data types (INT, REAL, BCD,  ...) into the DINT data type before you can convert them into the TIME data type. The "T_CONV" instruction is located in the block editor in the "Advanced" palette in the folder "Advanced Instructions > Date and Time".
Fig. 3 shows a conversion example of INT and REAL number values into the TIME data format.

Fig. 3

Conversion of the hardware data type HW_IO
The hardware data type HW_IO is for identifying a hardware module that STEP 7 (TIA Portal) uses to access the information of a module. This identification number is assigned automatically when creating the device configuration and is stored in the properties of the device in the HW Config. It is also available under the module name as system constant in the "PLC variables" list. In this way the module can be used directly through its name in the corresponding blocks.

Fig. 4
Fig. 4 shows an SCL program example for calling the instruction "IO2MOD". The variable "ChangeHWIO" includes the error code just in case the function has been parameterized incorrectly.

Further Information
More information on programming and parameterizing the instructions mentioned above is available in the STEP 7 (TIA Portal) Online Help. To obtain the Online Help you mark the instruction and press the "F1" key.

Creation Environment
The screens in this FAQ response were created with STEP 7 (TIA Portal) V15.

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit