Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grey code aaargh help.

Status
Not open for further replies.

zaphy2k2

Programmer
Dec 23, 2001
30
GB
Hi,

I need an algorithm for converting from grey code to binary code, all examples i can find are not for c++, or are seriously out of date and do not compile. anyone out there who has a nice quick solution for this i would be eternally grateful as this is really holding the project back. The ones ive seen do weird bitwise stuff, and i am not experienced enough in c++, im a java guy, but it must be in c.

cheers,
zaphy.
 
Yes, i have had a look, but cannot get any of the examples to work. (i cant get strtoul or ultoa to compile), and never get a binary back, only an integer. Does anyone have a working code sample they could show me please?
 
The computer store integer internally as binary.

When you run the examples, do you get the correct integer representation of the gray code? i.e. does gray code "1111" gives 10 (decimal)? If it does, then the examples do works. Now you just need a way to print out the binary representation of decimal 10 in a string. i.e. "1010".

I believe you should be able to write a function to convert an integer to a binary string.

Shyan


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top