A numeric literal declares a constant number (real or integer).
Numbers can be prefixed with a plus sign (+) character or minus (-) character. For example:
+5 or -25
A real number is declared when a period (.) character, or an exponent, is included. An exponent starts with either a latin capital letter E or a latin small letter e character. For example:
1.0
5E3
+1.0e-12.
The underscore (_) character can be used to separate digits. For example:
1_000_000
A prefix of 2#, 8#, or 16# is used to signify binary, octal or hexadecimal integers. For example:
2#1010101 is the binary representation of 85,
8#707 is the octal representation of 455, and
16#FFFF is the hexadecimal representation of 65535.
An integer value defaults to type DINT. A real value defaults to type LREAL. A prefix consisting of a type name followed by the number sign (#) character sets the type of numeric literal. For example:
SINT#0
REAL#55.
An integer can have both a type prefix and a radix prefix. For example:
SINT#16#7F
WORD#2#10_1010_1010.
Further examples of numeric literals:
Example | Interpretation |
---|---|
0 | DINT value 0 (zero) |
-10_000 | DINT value -10000 (minus ten thousand) |
+1_000_000 | DINT value 1000000 (one million) |
3.14169 | LREAL approximate value of PI |
1E6 | LREAL value 1000000 (one million) |
1e-2 | LREAL value 0.01 (one hundredth) |
2#100000 | DINT value 32 |
8#40 | DINT value 32 |
16#20 | DINT value 32 |
UINT#65535 | UINT value 65535 |
REAL#1 | REAL value 1.0 |
BOOL#0 | BOOL value FALSE |
BOOL#1 | BOOL value TRUE |
BOOL#FALSE | BOOL value FALSE |
BOOL#True | BOOL value TRUE |
Table 4 - IEC 61131-3 Second Edition.
Table 5 - IEC 61131-3 Third Edition.
To learn about data types that can be used as type prefixes for numeric literals.
To learn about other language Common Elements.
For a list of all Unicode character codes used in IEC 61131-3 code.
For the meaning of terms used in Fernhill SCADA.