SetBit - Manual - SIMATIC AX - System BitAccess Library - System.BitAccess,library

System.BitAccess library

Portfolio
SIMATIC AX
Product
SIMATIC AX
Software version
7.1.47
Edition
05/2024
Language
English (original)
Package Name
@ax/system-bitaccess

Sets the value of the specified bit of a bit string and returns the result.

Parameters:

Name Type Section Description
value T Input The bit string on which to operate.
index USINT Input Represents the position of the bit to set.
The valid range depends on the type of the value-variable:
- [0..7] for BYTE
- [0..15] for WORD
- [0..31] for DWORD
- [0..63] for LWORD
When specifying an invalid index, the function does not modify the value.
bitValue BOOL Input Set to TRUE to set the specified bit; set to FALSE to reset it.
Default: TRUE
T Return value Provides the resulting bit string.

The type T may be any of BYTE, WORD, DWORD or LWORD.

Example:

USING System.BitAccess;

PROGRAM SetBitProgram

    VAR

        value : WORD := WORD#2#0001_0001_0001_0001;

        bitValue : BOOL := false;

        result : WORD;

    END_VAR

    // 0001_0001_000->0<-_0001

    result := SetBit(

        value := value,

        bitValue := bitValue,

        index := USINT#4);

END_PROGRAM