1. Gray code conversion GRY/DGRY/GBIN/DGBIN
1. Gray code conversion GRY/DGRY/GBIN/DGBIN
1.1. Instruction Description
The GRY instruction converts the input single character value (IN) into the corresponding Gray Code and stores it in the OUT register.
The Double Character to Gray Code (DGRY) instruction performs the same operation, converting double characters.
Gray code to single character (GBIN) and Gray code to double character (DGBIN) perform the opposite operation, returning the Gray code to its normal value.
1.2. Gray code
Gray code is an encoding sequence with different elements, which can be generated by mathematical induction.
1-digit Gray code sequence: 0,1.
A 2-digit Gray code sequence consists of two 1-bit Gray code sequences. The first sequence is in positive order and preceded by 0, while the second sequence is in reverse order and preceded by 1:00,01 and 11,10.
3-digit Gray code sequence: 00000, 11010, and 110111101100.
Similarly, an n-bit Gray code sequence consists of two n-1 bit Gray code sequences.
16 bit integers can be mapped one by one to a 16 bit Gray code sequence, and vice versa, forming a bidirectional mapping. Same goes for 32-bit.
1.3. The valid operands of the instruction
1.3.1. Convert Single word to Gray(GRY)
| Input/Output | Data Type | operand | Description |
|---|---|---|---|
| IN | 16 bit integer | D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) | Input |
| OUT | 16 bit integer | D/CV/TV/AO/V/Z/FD, bit composite word (Y/M/C/T/S), local variable (LW) | output |
1.3.2. 双字转格雷码(GRYD)
| 输入输出 | 数据类型 | 操作数 | 描述 |
|---|---|---|---|
| IN | 32位整数 | D/CV/K/H/FD, 位合成字(X/Y/M/C/T/S), 局部变量(LD) | 输入 |
| OUT | 32位整数 | D/CV/FD, 位合成字(Y/M/C/T/S), 局部变量(LD) | 输出 |
1.3.3. Gray Code to Single Word(GBIN)
| Input/Output | Data Type | operand | Description |
|---|---|---|---|
| IN | 16 bit integer | D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) | Input |
| OUT | 16 bit integer | D/CV/TV/AO/V/Z/FD, bit composite word (Y/M/C/T/S), local variable (LW) | output |
1.3.4. Gray Code to Double word(GBIND)
| Input/Output | Data Type | operand | Description |
|---|---|---|---|
| IN | 32-bit integer | D/CV/K/H/FD, bit composite word (X/Y/M/C/T/S), local variable (LD) | input |
| OUT | 32-bit integer | D/CV/FD, bit composite word (Y/M/C/T/S), local variable (LD) | output |
1.4. Example
command table:
NETWORK 000
LD X000
GRYD D0 D20 // Convert D0D1 to Gray code and save it in D20D21.
图1 GRY