meta data for this page
  •  
INT type variables

In the case of the INT, which is the integer type, the definition becomes slightly more complex in terms of formal constraints because of the introduction of the sign bit. This means that the highest value of the variable's position, the first bit on the left, will represent the sign: if it is “1”, the variable indicates a negative number, whereas if it is “0”, it indicates a positive one.

Really, just for completeness, in the case of negative numbers, the program uses the so-called “two's complement” representation. That is, it first negates all the bits of the numerical value, i.e., it converts 0 to 1 and vice versa, and then adds 1 to the resulting value. This conversion means that the negative value cannot be read directly from the bit combination unless the conversion is performed again in the opposite direction:

two's complement by INT

As a result, Simatic only uses binary and hexadecimal notations for positive numbers, meaning that negative hexadecimal or binary values will not show the actual numerical value but instead the value based on the bit pattern. For example, A, which equals ten, will still be 16#A, but -A, which equals -10, will be displayed in WORD format as FFF6. This misunderstanding is resolved by the rule that hexadecimal and binary signals cannot have negative values in Simatic:

negative hexadecimal or binary values will not show the actual numerical value

In the above example, I tried to assign a value to an INT variable. It is clear that the compiler accepted the negative value when specified in decimal, but not when specified in hexadecimal or binary. Let's look at the contents of the INT variable in several forms:

DECSINT HEX (8-bit)SINT BIN (8-bit)INT HEX (16-bit)INT BIN (16-bit)
1216#7F2#0111_111116#007F2#0000_0000_0111_1111
116#012#0000_000116#00012#0000_0000_0000_0001
-116#FF2#1111_111116#FFFF2#1111_1111_1111_1111
-8516#AB2#1010_101116#FFAB2#1111_1111_1010_1011
-12816#802#1000_000016#FF802#1111_1111_1000_0000

The INT type is optimized for decimal handling; it can also be used in hexadecimal and binary forms, but in these cases, you need to pay close attention to the type's special characteristics.

Compared to byte and word type variables, this means that the maximum value of these variables is almost halved when dealing with decimal numbers. However, roughly the same magnitude can be used in the negative direction. For example, a one-byte-long SINT type will operate within the range -128 to 127, unlike the “plain” BYTE range of 0 to 255.

The letter “S” in the SINT definition stands for the word “short”, as the INT type is the default integer (16 bits), while SINT is short, with half the bit length—8 bits. The letter “D” represents the word “double,” with its 32 bits.

TypeNameBitMinimumMaximumValue range HEX *Value range DEC
SINTshort integer8-(27)27-10 .. 7F-128 .. 127
INTinteger16-(215)215-10 .. 7FFF-32.768 .. 32.767
DINTdouble integer32-(231)231-10 .. 7FFF_FFFF-2.147.483.648 .. +2.147.483.647
LINTdouble long integer64-(263)263-10 .. 7FFF_FFFF_ FFFF_FFFF-9.223.372.036.854.775.808 .. +9.223.372.036.854.775.807

* Negative number ranges are not supported in hexadecimal and binary formats.

UINT type variables

The unsigned UINT type (the letter U stands for unsigned) removes the hassle of dealing with negative values from the world of the INT type. It corresponds to basic types like BYTE, WORD, etc., in terms of value range, but with INT it indicates that we want to treat the contents of the variables as numeric values.

TypeNameBitMinimumMaximumValue range HEX *Value range DEC
USINTunsigned short integer80280 .. FF0 .. 255
UINTunsigned integer1602160 .. FFFF0 .. 65.535
UDINTUnsigned double integer3202320 .. FFFF_FFFF0 .. 4.294.967.295
ULINTUnsigned long integer6402640 .. FFFF_FFFF_ FFFF_FFFF0 .. 18.446.744.073.709.551.615

* Negative number ranges are not supported in hexadecimal and binary formats.