Question: Write a small C program that does the following: Includes the library Creates a 16-bit unsigned value with any arbitrary initial value Performs the gray
Write a small C program that does the following:
- Includes the
library - Creates a 16-bit unsigned value with any arbitrary initial value
- Performs the gray code conversion on your 16-bit value
- Prints the output in binary
A couple of hints:
- Obviously you can't work with a C variable like a Verilog vector. The bit twiddling operations will be useful here. Moreover, the XOR operation will be a useful replacement for an operation that wasn't specified as XOR but has the same output.
- There is no printf() formatting specifier that prints in binary. Here is a really simple function you can borrow: void PrintBinary(uint16_t n) { uint16_t i = 0; for (i = 1 << 15; i > 0; i = i / 2) { (n & i) ? printf("1") : printf("0"); } printf(" "); return; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
