Integer Types

Integer types are often used when defining the variables in an ST program. They allow you to specify the range of permissible values for a variable.

There are two varieties of integer type—signed and unsigned. Signed integers allow positive and negative numbers to be used, whereas unsigned integers only allow positive numbers. Each variety of signed and unsigned integer is suited to representing a specific range of values and bits (see table below).

Integer Type

Bits

Range

SINT (Short Integer)

8

-128 to +127

INT (Integer)

16

-32768 to 32767

DINT (Double Integer)

32

-231 to +231 -1

USINT (Unsigned Short Integer)

8

0 to 255

UINT (Unsigned Integer)

16

0 to 216-1

UDINT (Unsigned Double Integer)

32

0 to 232-1

When you add integers to your Logic programs, you need to use a suitable type of integer. You should consider the possible range of counts, then use the table above to determine which type of integer is appropriate for covering the expected range.

When using literal values in a program, you need to pay special attention to the integer type you use, as literal values use the smallest type of integer possible. For example, if you use the literal value 2, it will be a SINT by default. As the result of a calculation is the same type as the largest operand in the calculation, this can cause confusion due to the result type not supporting the range needed for the result of the calculation. For example, for 2**7 (which is 27), you may expect 128 as a result, but the result is -1. This is because the smallest type of integer for 2 is a SINT and the smallest type of integer for 7 is also SINT. As the type of value for the highest operand (7) is SINT, the result of the calculation is also SINT. But as SINT can only support the range -128 to +127, it cannot store the result of 128. Instead, it returns -1.

For this reason, you need to be careful when defining literal values and you should consider the required integer type for the result. There are two possible ways of working around these situations:


Disclaimer

ClearSCADA 2017 R3