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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started