Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Binary & Gray Code

Status
Not open for further replies.

shermaine

New Member
May i know the differences between binary and gray code?
Is there any best way of remembering the gray code?
Pls advise.
Thanks.
 
shermaine said:
May i know the differences between binary and gray code?
Is there any best way of remembering the gray code?
Pls advise.
Thanks.

Binary is straightforward, for 3 bit number 000, 001, 010, 011 etc...

In Gray code, only one bit position changes from adjacent codes

000, 001, 011, 010 like so.. when you write out all the bit sequences and arrange them in such a way so that each adjacent code has only 1 bit changed from the last, you will have the gray code sequence.

I don't think there is a way to remember it other than knowing the 1 bit difference rule. I suppose when you use it alot, you will have it memorized.
 
Twisted ring counters also count in Gray code.

For example, a 3 stage TRC counts as follows

000, 100, 110, 111, 011, 001, 000

Len
 

Attachments

  • Counter-Twisted_Ring.gif
    Counter-Twisted_Ring.gif
    7.6 KB · Views: 519
As Optikon said in his response, there are many possible Gray codes.

The definition of a Gray code is (as Optikon said) that only one bit changes at each step.

A 4 bit Twisted Ring Counter would have the following sequence:-

0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001, 0000, etc.

Gray codes are also used in position sensors. Say you want to convert the angular position of a shaft into a digital signal. You could attach a transparent disc to the shaft with say a 4 bit code on the disc (eg. a photographically produced transparent disc with the ones and zeros represented by transparent and non transparent sectors. There would be 4 LED/Photo diode (or transistor) pairs to detect the data.

If you used binary numbering, it would not be possible to detect the exact code at some transistions since often 2 or more bits change at once.

Whereas, with a Gray code, since only one bit changes at each transition, there is no ambiguity.

Len
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top