Talk:Gray code

From Rosetta Code
Revision as of 14:53, 18 March 2011 by Rdm (talk | contribs) (→‎D encoding)

D encoding

Am I reading the D encoding right? Gray code is just the number xor'd with its right shifted value? If so, my mind is blown. --Mwn3d 04:41, 18 March 2011 (UTC)

It has been stated in wikipedia :) dingowolf 11:17, 18 March 2011 (UTC)
Wow. Reading is hard. I'm definitely changing the Java version. --Mwn3d 13:04, 18 March 2011 (UTC)
The only tricky bit in decoding is that you need the previously decoded bit to decode the next one. That makes everything just that little bit messier (as evidenced by the many strategies shown for decoding!) though it does mean that everything admits a rather nice decode loop if you're cunning enough. (Decoding tables? O RLY? SRSLY?) –Donal Fellows 14:47, 18 March 2011 (UTC)
When I use a previously decoded bit in the exclusive or, I get the wrong answer. When I use the undecoded bits, I get the right answer. Unless I am doing something horribly wrong: The leftmost bit is unchanged. After that, every bit is the binary difference (exclusive or) of two adjacent undecoded bits. --Rdm 14:53, 18 March 2011 (UTC)

Decoding a bitstream

Decoding individual symbols looks trivial; you could do it with a lookup table. What would decoding a Gray code bitstream look like? Finding the the beginning of each symbol might be a tad trickier. --Michael Mol 13:13, 18 March 2011 (UTC)