# 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)

Struggling to find relevant content? Order a custom essay on
Sample Projects in C#: Consecutive Numbers in Gray Code Sequence
Let our experts save you the hassle
• 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:

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 `#include ` `const` `int` `N = 5;``//amount of sybmols in the number` `bool` `checkInput(``char` `arr[])` `{` `    ``bool` `error = 0;` `    ``for` `(``int` `i = 0; i < 4; i++) ` `    ``{` `        ``if` `((arr[i] != ``'1'``) && (arr[i] != ``'0'``)) ` `        ``{` `            ``std::cout << ``"Error in "` `<< i + 1 << ``"'th symbol\n"``;` `            ``error = ``true``;` `        ``}` `    ``}` `    ``return` `error;` `}` `void` `checkGray(``char` `a[], ``char` `b[])` `{` `    ``int` `sum2(0), sum1(0);` `    ``for` `(``int` `i = 0; i < 4; i++) {` `        ``sum1 += a[i];` `        ``sum2 += b[i];` `    ``}` `    ``if` `(sum1 == sum2 + 1 || sum2 == sum1 + 1)std::cout << ``"Numbers are consecutive\n"``;` `    ``else` `std::cout << ``"Numbers aren't consecutive"``;` `}` `int` `main()` `{` `    ``char` `a[N], b[N];``//Gray codes` `               ` `    ``std::cout << ``"Input the first number: "``;` `    ``std::cin.getline(a, N);``//read the first number` `    ``if` `(checkInput(a) == 1)``//check for only 0 and 1 in the number` `    ``{` `        ``system``(``"pause"``);` `        ``exit``(1);` `    ``}` `    ``std::cout << ``"Input the second number: "``;` `    ``std::cin.getline(b, N);``//read the second number` `    ``if` `(checkInput(b) == 1)``//check for only 0 and 1 in the number` `    ``{` `        ``system``(``"pause"``);` `        ``exit``(1);` `    ``}` `    ``checkGray(a, b);``//check for consecutive numbers` `    ``system``(``"pause"``);` `    ``return` `0;` `}`

Reference

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.

Calculate the price
Pages (550 words)
\$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
Sign up, place your order, and leave the rest to our professional paper writers in less than 2 minutes.
step 1
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
s
Get personalized services with GPA Fix
One writer for all your papers
You can select one writer for all your papers. This option enhances the consistency in the quality of your assignments. Select your preferred writer from the list of writers who have handledf your previous assignments
Same paper from different writers
Are you ordering the same assignment for a friend? You can get the same paper from different writers. The goal is to produce 100% unique and original papers
Copy of sources used
Our homework writers will provide you with copies of sources used on your request. Just add the option when plaing your order
What our partners say about us
We appreciate every review and are always looking for ways to grow. See what other students think about our do my paper service.
Nursing
Awesome work!!!!!!
Customer 452453, March 24th, 2021
Medicine
Thank you for the great services
Customer 452635, April 24th, 2022
Social Work and Human Services
Excellent Work!
Customer 452587, November 30th, 2021
Criminal Justice
Great work! Followed directions to the latter.
Customer 452485, September 1st, 2021
Other
GOOD
Customer 452813, July 10th, 2022
Other
AWESOME
Customer 452813, June 21st, 2022
Nursing
The writer went above and beyond as usual. Always a great experience with these writers.
Customer 452707, December 4th, 2022
Nursing
Great writer (Proske). I highly recommend
Customer 452531, July 10th, 2021
Psychology
Thgank you
Customer 452905, December 11th, 2022
Nursing
Thank you so much. I didn't know where to start and you did an amazing job. Thanks and have a great night.
Customer 452925, March 16th, 2023
Psychology
Excellent!!!!
Customer 452587, July 28th, 2021
Human Resources Management (HRM)
Thank you
Customer 452701, July 26th, 2023