Bitwise un-Gray

Converts a reflected Gray code value back into a normal binary number — the inverse of Bitwise Gray.

Why you need this. Many rotary encoders, absolute shaft encoders and linear position sensors output their position as Gray code rather than plain binary. Gray code is designed so that only one bit ever changes between adjacent positions, which prevents the sensor from being misread while its bits are switching (see Bitwise Gray for the full explanation). The trade-off is that the raw Gray value is not the position number — for example the Gray reading 110 actually means position 4, not 6. This module performs the decoding so you get back the real position you can compute with.

position Gray reading (raw) after un-Gray
2 011 010 = 2
3 010 011 = 3
4 110 100 = 4
5 111 101 = 5

Notice the raw Gray readings look scrambled (011, 010, 110, 111), but after un-Gray they come out as the clean sequence 2, 3, 4, 5.

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.

Settings

in

Input value.

out

Output value.

Example — reading a rotary encoder

A 4-bit absolute rotary encoder is wired to Usine as four on/off inputs (one per encoder track). As the shaft turns it emits Gray code. To convert that raw signal into a usable 0–15 position, chain:

4 encoder bits  ->  [Bitwise Bit Array to Bitwise]  ->  [Bitwise un-Gray]  ->  [Bitwise to Integer]  ->  position 0..15

Turning the shaft one detent at a time, the raw bits and the decoded position look like this:

shaft step raw encoder bits (Gray) un-Gray out position
rest 0000 0000 0
+1 0001 0001 1
+1 0011 0010 2
+1 0010 0011 3
+1 0110 0100 4

Only one physical track flips at each step (0001001100100110), so the reading never glitches, yet the decoded position advances cleanly 0, 1, 2, 3, 4. Feed that position into a fader, a selector, or any parameter you want the knob to control.

Common Settings

info

show manual

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

Description of the module for internal help purposes only. The description is not displayed in the interface.

ID's

visible only in god mode, see setup-panel-tab-expert.

unique ID

Current private ID for this control used to identify the object.

preset ID

Current private preset ID for this control used for presets.

recreate ID

If you experience difficulties in Polyphonic mode, try to recreate new id(s) with this button.

repair ID s

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.

Object Remote Address

absolute

Absolute remote address. see objects-address.

local

Local to the current patch remote address. see objects-address.

user addr

User defined remote address. see objects-address.

See also

version 7.0.250121

Edit All Pages