Sample Projects in C#: Consecutive Numbers in Gray Code Sequence
Consecutive Numbers in Gray Code Sequence
- The reflected binary code (RBC), also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one bit (binary digit). The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems. (en.wikipedia.org, 2002)
- So we need to implement a program in C++ that will successively read two numbers which are represented as four-bit numbers. And then it should determine whether these to numbers are consecutive in the Gray code.
- Two binary reflected Gray code neighbors differ by only one bit. But, it doesn’t mean that two Gray codes differing by one bit are neighbors (a => b does not mean that b => a).
- To determine whether two Gray codes are neighbors, we have to check whether previous(a) = b OR next(a) = b. For a given Gray code, you get one neighbor by flipping the rightmost bit and the other neighbor bit by flipping the bit at the left of the rightmost set bit. For the Gray code 1010, the neighbors are 1011 and 1110 (1000 is not one of them).
- Whether you get the previous or the next neighbor by flipping one of these bits actually depends on the parity of the Gray code. However, since we want both neighbors, we don’t have to check for parity.
Screenshots of working program:
Code listing with comments:
Gray code. (2002, April 27). Retrieved July 08, 2016, from https://en.wikipedia.org/wiki/Gray_code
Our sample projects in C# were completed just for demonstration of our possibilities, so you shouldn’t use it as your work. You can also enjoy reading one of our C# programming code examples. Better make the order right now and be satisfied with your assignment!
If you need to complete something similar to our sample projects in C# and you don’t know how to cope with this don’t panic. GPA Fix was established right for students like you. Our experts are able to provide you with qualified help to raise your GPA any time you need it. The only thing you need to do is to specify your requirements accurately. During the whole process you’ll be able to keep in touch with your expert via live chat. Also, you have the ability to track order’s progress.