Constants

Top  Previous  Next

Constants can take the form of integer, floating-point of string values.
For integers it is possible to specify the value in decimal, binary, octal or hexadecimal notation. This is done by adding 2#, 8# or 16# before the actual value.
 

Floating-point constants are identified with a decimal '.' indicator, such as: '55.00' or just '55.'
The differentiation is important as '55' will be treated as a integer value whether 55.0 will be treated as a floating-point value.

 

When defining integer or floating-point constants, it is possible to include '_' (underscore) at any position in the number to enhance readability.

 

Example:

INCLUDE rtcu.inc
 
VAR
  var : INT;
  varf : FLOAT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  var := 4711; // This will assign the value 4711 to var.
  var := 47_11; // This will also assign the value 4711 to var.
 
  var := 2#10_0010; // This will assign the binary value 100010 to var.(100010 equals 34 in decimal notation)
  var := 8#476;     // This will assign the octal value 476 to var.(476 equals 318 in decimal notation)
  var := 16#2F32;   // This will assign the hexadecimal value 2F32 to var.(2F32 equals 12082 in decimal notation)
  varf := 4711.0;   // This will assign the value 4711.0 to varf.
  varf := 4_711.56; // This will assign the value 4711.56 to varf.
 
END;
 
END_PROGRAM;