
8-3
8-3. Application examples of variables
8-3-1. Byte variable
(1) Group input
A byte variable that stores a 1-byte (means 8 bits) value.
When an 8-bit group input is received by the byte variable, the terminals of the group input are allocated to and stored in
ones to 128s of the byte variable as binary number respectively. The value is the sum of the denary number(s) of the
digit(s) whose terminal is(are) “ON”.
8-bit group input
D07 D06 D05 D04 D03 D02 D01 D00
128
64
32
16 8 4 2 1
Value
Example
1
OFF OFF OFF OFF OFF OFF OFF OFF
0
Example
2
OFF OFF OFF OFF OFF OFF OFF ON
1
Example
3
OFF OFF OFF ON OFF ON OFF ON
21
Example
4
OFF ON ON OFF ON OFF ON OFF
106
Example
5
ON ON ON ON ON ON ON ON
255
If the byte variable is used for 4-bit group terminals, the terminals are allocated to and stored in ones to 8s of the byte
variable. As for output, 16s to 128s are ignored (or treated as “OFF”). As for input, 16s to 128s are treated as “OFF”.
Ignored
4-bit group input
D03
D02
D01
D00
Output
value
128
64
32
16
8 4 2 1
Example 1
0
OFF
OFF
OFF
OFF
OFF OFF OFF OFF
Example 2
1
OFF
OFF
OFF
OFF
OFF OFF OFF ON
Example 3
21
OFF
OFF
OFF
ON
OFF ON OFF ON
Example 4
106
OFF
ON
ON
OFF
ON OFF ON OFF
Example 5
255
ON
ON
ON
ON
ON ON ON ON
(2) Logic operation
It is possible to use the byte variable in logic operation. In that case, logic operation is executed with each bit.
For example, logic operations of byte variables LB001=3 and LB002=10 are
AND (Logical multiplication):
LB001
0000 0011
LB002
0000
1010
LB001 AND LB002
0000 0010
= 2
OR (Logical AND):
LB001
0000 0011
LB002
0000
1010
LB001 OR LB002
0000 1011
= 11
XOR (Exclusive OR):
LB001
0000 0011
LB002
0000
1010
LB001 XOR LB002
0000 1001
= 9
NOT (Logical NOT):
LB001
0000 0011
NOT LB001
1111 1100
= 252
The NOT operation is also executed for all 8 bits. To execute a NOT operation for 4 bits, AND the result byte of
NOT operation and a byte variable whose value is 15 (00001111 in binary).