Logical block that revolutions the value of a specific bit in a field.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
Data |
BYTE USINT SINT WORD UINT INT DWORD UDINT DINT |
Variable whose bit will be tested |
EN |
BOOL |
Block enabling |
|
Position |
BYTE USINT |
Position of the bit that will be changed |
|
VAR_OUTPUT |
Q |
BOOL |
Value of the tested bit |
Operation
This block when it has a TRUE value in EN, sends to the output Q the bit value indicated in Position in the Data variable.
When EN has FALSE value, Q also receives FALSE.
|
NOTE! It is important to notice that Position is within the range of values of bits corresponding to variable type in Data. For example: if Data is a BYTE, it has 8 bits, and Position must contain a value between 0 and 7. |
Block Flowchart

Example in Ladder

The example above sets the bit value of zero position of AUX, whose initial value is 74 (0100 1010 in binary) to the output Q. Since this bit has value 0, the output is disabled.

The example above sets the value of the bit of position three of AUX to the output Q. Since this bit has value 1, the output is enabled.

The example above sets the bit value of position ten of AUX to output Q. Since AUX is a variable of BYTE type, it has only eight bits. Thus, the example above creates a runtime error in the block and therefore the output is disabled.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR AUX : BYTE := 2#0100_1010; POS : BYTE := 3; END_VAR
DO1 := FB_TESTBIT( EN:=DI1, Data:=AUX, Position:=POS);
|
|---|