meta data for this page
This is an old revision of the document!
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:
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:
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:
| DEC | SINT HEX (8-bit) | SINT BIN (8-bit) | INT HEX (16-bit) | INT BIN (16-bit) |
|---|---|---|---|---|
| 12 | 16#7F | 2#0111_1111 | 16#007F | 2#0000_0000_0111_1111 |
| 1 | 16#01 | 2#0000_0001 | 16#0001 | 2#0000_0000_0000_0001 |
| -1 | 16#FF | 2#1111_1111 | 16#FFFF | 2#1111_1111_1111_1111 |
| -85 | 16#AB | 2#1010_1011 | 16#FFAB | 2#1111_1111_1010_1011 |
| -128 | 16#80 | 2#1000_0000 | 16#FF80 | 2#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.

