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 LWORDWhen 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