Skip to main content

Integers and Bit strings

Description

Integers and bit strings are first defined by the number of bytes they consume. Secondly, they are described by what they represent. Integers are signed (representing positive and negative values) or unsigned (only positive values inclusive of 0). A bit string BYTE / WORD / DWORD / LWORD represents a collection of bits.

Data TypeBytesMinimum ValueMaximum Value
BYTE116#016#ff
USINT10255
SINT1-128127
WORD216#016#ffff
UINT2065535
INT2-3276832767
DWORD416#016#ffff_ffff
UDINT404,294,967,295
DINT4-2,147,483,6482,147,483,647
LWORD816#016#ffff_ffff_ffff_ffff
ULINT8018,446,744,073,709,551,615
LINT8-9,223,372,036,854,775,8089,223,372,036,854,775,807

Declaration

Number Systems

The following number systems are supported as described by the IEC 61131-3 standard.

Number SystemBaseRepresented by
Binary20 / 1
Octal80 through 7
Decimal100 through 9
Hexadecimal160 through 9, A through F

Literals

There are many methods for assigning integer literal values.

a : INT;

// Use the 2# prefix to indicate binary number system
a := 2#10;
print(a);
printf(a, 'b2');

// Use the 8# prefix to indicate the octal number system
a := 8#107;
print(a); // NOTE : currently no formatter for octal numbers in printf function


// Standard decimal number system
a := -10;
print(a);

// Use the 16# prefix to indicate the hexadecimal number system
a := 16#A;
print(a);
printf(a, 'x');

For large numbers it can help to use the underscore _ character to provide some separation. Note that commas are not allowed within the literals.

a : INT;

a := 2#01001000_11001111;
a := -32_768;