Converts a standard binary number into its reflected Gray code.
What is Gray code? It is a way of numbering things so that going from one value to the next always changes exactly one bit. Ordinary binary does not have this property: counting from 3 (011) to 4 (100) flips all three bits at once. Gray code re-orders the bit patterns so every step is a single-bit change.
Compare the two encodings side by side:
| number | binary | Gray |
|---|---|---|
| 0 | 000 |
000 |
| 1 | 001 |
001 |
| 2 | 010 |
011 |
| 3 | 011 |
010 |
| 4 | 100 |
110 |
| 5 | 101 |
111 |
| 6 | 110 |
101 |
| 7 | 111 |
100 |
In the binary column several bits jump at the boundaries (3→4 changes all three). In the Gray column only ever one bit changes from each row to the next.
Why does that matter? When a physical sensor reads several bits at the same instant, the bits never switch perfectly together. With plain binary, during the 3→4 transition the reader can momentarily see a bogus value like 111 (7) or 000 (0) while the bits are settling — a glitch. Because Gray code changes only one bit per step, there is no in-between value to misread, so the reading is always either the old value or the new one. This is exactly why many rotary encoders, linear position sensors and absolute shaft encoders output Gray code.
Bitwise flows are not directly compatible with data flows. You must use integer-to-bitwise to set bitwise inlets and bitwise-to-integer to retrieve outlet values. Bitwise inputs are in hexadecimal format (0123456789ABCDEF). ie. $FA234B, $FFFF, etc. Bitwise flows are compatible with Color flows.
Input value.
Output value.
Feed a normal binary count in and read the Gray-coded equivalent out — note that only one bit changes between consecutive rows:
| in (binary) | in | out (Gray) | out |
|---|---|---|---|
010 |
$02 | 011 |
$03 |
011 |
$03 | 010 |
$02 |
100 |
$04 | 110 |
$06 |
101 |
$05 | 111 |
$07 |
Suppose you have a 4-bit absolute rotary encoder wired to Usine as four on/off inputs. As the shaft turns it emits Gray code, so the raw reading is not a usable position number yet. To turn it into a clean 0–15 angle:
4 encoder bits -> [Bitwise Bit Array to Bitwise] -> [Bitwise un-Gray] -> [Bitwise to Integer] -> position 0..15
Use Bitwise un-Gray for decoding the encoder (this is the common direction). This Bitwise Gray module does the opposite — it encodes a plain number into Gray code, which is useful when you need to drive a Gray-coded device or simulate an encoder signal:
position 0..15 -> [Bitwise Gray] -> [Bitwise to Bit Array] -> 4 output bits (Gray-coded)
Opens the web browser to display information or help about the selected object, if it exists.
For more details about information/help creation, see create-help-file.
Description of the module for internal help purposes only. The description is not displayed in the interface.
visible only in god mode, see setup-panel-tab-expert.
Current private ID for this control used to identify the object.
Current private preset ID for this control used for presets.
If you experience difficulties in Polyphonic mode, try to recreate new id(s) with this button.
Each Patch shared on the local network uses its own ID (identification number). If you experience issues of Patches that don't send information to the good target, this button will rebuild all these id's.
Absolute remote address. see objects-address.
Local to the current patch remote address. see objects-address.
User defined remote address. see objects-address.
version 7.0.250121
Edit All Pages