Siemens Industry Online Support
Siemens AG
Entry type: Application example Entry ID: 29851674, Entry date: 10/24/2012

Tool collection of functions for bit, number and mathematical operations

  • Entry
  • Associated product(s)

Tool collection of functions for bit, number and mathematical operations

This module provides a tool collection of operations.
The functions are grouped in two categories and are briefly described below.

The detailed description of each function example is available in the appended documentation with the following structure:

  • Description of the functions
  • Block parameter lists of the functions
  • Example of an application
  • Technical data

The code for the functions and examples in form of a STEP 7 project or a STEP 7 library can be downloaded.

Brief overview:


Bit and number operations

  • Random number generator
    The RANDOM function is a random number generator implemented as 16-bit feedback shift register. The random numbers are in the range of
    -32768 to +32767.
  • Determination of the parity of data elements
    The PARITY function (FC 12) allows the parity determination of byte, word or double word elements and DB blocks for the memory areas “input”, “flag” and “data block”.
  • Determination of the active bit position in a flag word
    The “CalcBitPos” function determines the position of the set bit in an input data word (16 bit) and returns it as an INT value via the OUT parameter “bit_pos”.
  • Edge detection in a 32-bit field
    The function “Monitor32” checks whether a bit has changed in a 32-bit data word since the last function call.
  • Incremental counter with a limit of 2,147,483,647
    The function block “Counter” (FB 2) enables you to implement the incremental counting function with a limit of 2,147,483,647.


Mathematical operations

  • Calculate the xth root of a REAL number
    The function “X-ROOT” calculates the xth root from an input floating-point number (REAL). The result is of type REAL and is returned via an OUT parameter (result).
  • Calculation of statistical values in automation systems
    The SPC01 function calculates statistical values, namely the highest value, the lowest value, the arithmetic mean and the standard deviation.
  • Matrix operations in SIMATIC systems
    Library with functions for implementing various matrix operations, such as addition, subtraction, multiplication, inversion und transposition.
  • Multidimensional interpolation
    Function blocks for the interpolation of functions with one, two or three independent variables.


Content of Downloads Download
Documentation 29851674_Operationen_Bausteine_V10_e.pdf ( 1090 KB )
SIMATIC STEP 7 code of the function examples 29851674_OperationenV10.zip ( 1581 KB )


Current test environment:

Components Test environment
PC platform 2.33 GHz 2GB RAM
Operating system Windows XP SP2
SIMATIC STEP 7 V5.4 with SP3 + HF1





04/2009 First edition


Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit