Question: Write a function called Gray2binary that takes an unsigned character and returns an unsigned character. The returned value is the binary equivalent of the input

Write a function called Gray2binary that takes an unsigned character and returns an unsigned character. The returned value is the binary equivalent of the input byte, assuming it was Gray code. To convert from Gray code to binary, compute the bits from left to right as follows: Each bit of the result is an exclusive-OR of that bit position of the original number with the newly computed binary result bit to the left of that bit position. That is, if B_i and G_i are the i-th bits of the binary and Gray code values, respectively, then B_i = G_i ^ B_i+1. Assume a leading zero is in front of the original number, so the MSB (most significant bit) of the result is the same as the MSB of the original. For example, 0b00000000, 0b11000000, 0b00001000, 0b00101010, and 0b01111111 return 0b00000000, 0b10000000, 0b00001111, 0b00110011 and 0b01010101, respectively.

Instructor Notes: CodeLab doesn't allow binary constants (0b00101100). You must enter them as hexadecimal (0x2C). Please help me with this!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!