Numeric Constants

Numerical values can by binary numbers, octal numbers, decimal numbers or hexadecimal numbers. If an integer value is not a decimal number, its base must be written before the integer constant, followed by the hash symbol (#). For hexadecimal numbers, the numerals for the numbers 10 to 15 are represented by the letters A-F, as usual.

You can use underscores within a numerical value.

Examples:

14

Decimal number

2#1001_0011

Binary number

8#67

Octal number

16#A

Hexadecimal number

DINT#16#A1

Typed data type DINT# and base 16# combined.

The type of this numerical values can be BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL or LREAL.

Numeric Constants 1:

Implicit conversions from "larger" to "smaller" types are not allowed. You cannot simply use a DINT variable as an INT variable. To do this, you must use a type conversion function.

Numeric Constants 2:

Since number constants are generally treated as integer values, in divisions the constant has to be specified as a floating-point number, in order to avoid losing the rest. Example: Division 1/10 results in 0, division 1.0/10 results in 0.1.

See also: