Bitwise Gray

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.

Settings

in

Input value.

out

Output value.

Example — encoding

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

Example — driving a rotary encoder display

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)
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