PLC Archive:Gray Code to Binary Conversion

From ControlWiki

Jump to: navigation, search

Gray Code to Binary Conversion

contributed by: Anthony Kerstens

Link to File

Click here to view program file.


This file was submitted by Anthony Kerstens for converting grey code to binary. It's generalized to use a full 16 bits, but could be shortened or expanded to suit the application. The MSB is taken directly, and the algorithm for subsequent bits is the same for the remaining bits regardless of the number.

The logic example is programmed with symbols G15 to G00, and B with bits /15 to /0. G15 to G00 are gray code inputs from an encoder or other such device. B is the binary integer file, with individual bit B/15 to B/0. The G15_MSB is taken directly. Subsequent G bits are XOR'd with the previous B bit. ie. B/n = Gn xor B/(n+1).


For all material in the PLC Archive, our site disclaimer applies. You take full responsibility for the application of any code appearing on this site, as we have made no engineering evaluation of the code nor are we, or the author, familiar with the details and risks inherent in your application.

Personal tools