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

Button. Opens the manual page of the selected object (or of its parent module for a control) in the web browser. If no page exists for this object, an error is traced in the trace panel.

For more details about information/help creation, see create-help-file.

description

Free multi-line text attached to the module, saved with the patch. It is only meant as an internal note for the patch designer: it is not displayed in the interface.

ID's

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

unique ID

Read-only, not saved. Current private numeric ID of the object, used internally to identify it (for example as the target of a bind ID).

preset ID

Read-only, not saved. Private ID used to store and recall the values of this control in presets.

recreate ID

Button. Generates a new unique ID, original ID and preset ID for the object. Use it if you experience difficulties in Polyphonic mode or if two objects share the same ID. Preset values and binds referring to the old IDs are lost.

Object Remote Address

absolute

Read-only, not saved. Absolute address of the object in the Usine objects tree, built from the workspace root. This is the address to use to reach the object from scripts, the objects panel or remote messages. Only shown for objects that are registered in the objects list. See objects-address.

local

Read-only, not saved. Address of the object relative to the current patch, valid inside that patch only. See objects-address.

user addr

Free user-defined address for the object (empty by default). When set, the object is also registered in the objects tree under this name, so it can be reached independently of its position in the workspace (the value is also reported in the mouse-over and mouse-down chunks). Changing it rebuilds the objects list. Only available on objects that support a user address. See objects-address.

See also

version 7.0.250121

Edit All Pages