Numeric Literals

Help Contents

Introduction

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.

Examples of Numeric Literal

Further examples of numeric literals:

ExampleInterpretation
0DINT value 0 (zero)
-10_000DINT value -10000 (minus ten thousand)
+1_000_000DINT value 1000000 (one million)
3.141592654LREAL approximate value of PI
1E6LREAL value 1000000 (one million)
1e-2LREAL value 0.01 (one hundredth)
2#100000DINT value 32
8#40DINT value 32
16#20DINT value 32
UINT#65535UINT value 65535
REAL#1REAL value 1.0
BOOL#0BOOL value FALSE
BOOL#1BOOL value TRUE
BOOL#FALSEBOOL value FALSE
BOOL#TrueBOOL value TRUE

Standards Compliance

IEC 61131-3 Second Edition: Table 4.

IEC 61131-3 Third Edition: Table 5.

Further Information

Elementary Data Types

To learn about data types that can be used as type prefixes for numeric literals.

Common Elements

To learn about other language Common Elements.

Character Codes

For a list of all Unicode character codes used in IEC 61131-3 code.

Glossary

For the meaning of terms used in Fernhill SCADA.