How to Calculate Gray Code

Save

Gray code, also known as reflected binary code, expresses all its values as a sequence of 1s and 0s. Unlike binary code, each value differs from the previous one by only a single bit. This has many practical applications, particularly where multiple simultaneous bit changes would result in errors. Gray codes can have any number of bits, and new Gray codes can be calculated from binary codes that have one bit less than the proposed Gray code.

  • Decide on the number of bits that will make up your Gray code. For example, suppose you want a Gray code that is 3 bits long. The number of bits determines how many different values the Gray code can represent. To find out how many values a Gray code can represent, raise 2 to the power of the number of bits that make up the code. For example, a 3-bit Gray code can represent eight different values.

  • Write out the binary code for a sequence that is 1 bit less than your Gray code (see Resources for more on binary code). If your Gray code has 3 bits, you will write out the binary code for a 2-bit binary code, like this:

    00, 01, 10, 11

  • Add a leading zero to all the numbers in the sequence you just wrote, like this:

    000, 001, 010, 011

  • Write the binary code again in reverse order, like this:

    11, 10, 01, 00

  • Add a leading one to all the numbers in the sequence you just wrote, like this:

    111, 110, 101, 100

  • Concatenate the two lists together. You now have a 3-bit Gray code, which looks like this:

    000, 001, 010, 011, 111, 110, 101, 100

References

  • Photo Credit Jupiterimages/Photos.com/Getty Images
Promoted By Zergnet

Comments

Resources

You May Also Like

  • Types of Digital Computers

    Digital computers are programmable machines that use electronic technology to generate, store and process data. Two terms, positive "1" and nonpositive "0,"...

  • How to Call a USA Area Code

    When calling the United States from countries other than Canada, you need more than just the area code and the number. If...

  • How to Calculate the Hamming Code

    Calculate the first parity bit. Starting with the first bit, read one bit, then skip one bit and repeat, while counting the...

Related Searches

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!