0% found this document useful (0 votes)
38 views

Gray Code

A Gray code is an encoding of numbers where adjacent numbers differ by a single digit. Gray codes are useful for hardware that may cause errors during transitions between numbers, as Gray codes ensure only one bit changes between values. Gray codes can be constructed recursively by taking the previous code, adding the reverse, and prefixing with 0 or 1. There are different types of Gray codes beyond binary, and they have applications in encoders, error detection, and more.

Uploaded by

James Macalalad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Gray Code

A Gray code is an encoding of numbers where adjacent numbers differ by a single digit. Gray codes are useful for hardware that may cause errors during transitions between numbers, as Gray codes ensure only one bit changes between values. Gray codes can be constructed recursively by taking the previous code, adding the reverse, and prefixing with 0 or 1. There are different types of Gray codes beyond binary, and they have applications in encoders, error detection, and more.

Uploaded by

James Macalalad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Gray Code

A Gray code is an encoding of numbers so that adjacent numbers have a single digit differing by 1.
The term Gray code is often used to refer to a "reflected" code, or more specifically still, the binary reflected
Gray code.
The reflected binary code or Gray code is an ordering of the binary numeral system such that two
successive values differ in only one bit (binary digit). Gray codes are very useful in the normal sequence of
binary numbers generated by the hardware that may cause an error or ambiguity during the transition from
one number to the next. So, the Gray code can eliminate this problem easily since only one bit changes its
value during any transition between two numbers.
Gray code is not weighted that means it does not depends on positional value of digit. This cyclic
variable code that means every transition from one value to the next value involves only one bit change.
Gray code also known as reflected binary code, because the first (n/2) values compare with those of
the last (n/2) values, but in reverse order.

Constructing an n-bit Gray code


n-bit Gray code can be generated recursively using reflect and prefix method which is explained as
following below.
 Generate code for n=1: 0 and 1 code.
 Take previous code in sequence: 0 and 1.
 Add reversed codes in the following list: 0, 1, 1 and 0.
 Now add prefix 0 for original previous code and prefix 1 for new generated code: 00, 01, 11, and 10.
Therefore, Gray code 0 and 1 are for Binary number 0 and 1 respectively. Gray codes: 00. 01, 11, and 10 are
for Binary numbers: 00, 01, 10, and 11 respectively. Similarly you can construct Gray code for 3 bit binary
numbers:
Therefore, Gray codes are as following below,

For n = 1 bit For n = 2 bit For n = 3 bit


Binary Gray Binary Gray Binary Gray

0 0 00 00 000 000

1 1 01 01 001 001

10 11 010 011

11 10 011 010

100 110

101 111

110 101

111 100

Decimal Binary Gray Code

0 000 000

1 001 001

2 010 011

3 011 010

4 100 110

5 101 111

6 110 101

7 111 100
Types of Gray Codes
There are also other types of Gray codes, like Beckett-Gray code, Single track Gray codes etc.
 N-ary Gray code, where non-Boolean values are included like sequences of 1, 2, 3.
 Two dimensional (n,k) Gray codes are used for error correction.
 Balanced Gray codes has equal transition counts.
Uses of Gray codes
Gray codes are used in rotary and optical encoders, Karnaugh maps, and error detection.

You might also like