Question: i am really stuck on writing the second function computegrey(g) the source file reads in the letter A and B in the file and then

A. Write a function int computeGrayInt (n, k) to compute & return the integer corresponding to the gray number that appears in position k of the n-bit Gray Code using bit manipulation. There is an easy trick for this one, you do not have to compute all the Gray bit numbers. Instead, shift k right 1 bit than use bit-wise xor on k and the shifted number. For example, n = 3, k= 7 k 111 right shift 011 100 4 This can be done in one line of code. xor B. Write a function int computeGrayPostion (g), that when given a gray code, computes its position k in the n-bit Gray Code. The position k is the base 10 integer representation of the binary code. Use the bit manipulation algorithm above. I will give you hints in class on how to code this. 8 101 100 110 61 pos. 8 1 1 1 1 1 1 1 1 10 1 0 1 0 1 89th position If the line starts with an A, then there will follow 2 integers: number of bits n (1 sn 38) and position ko sk
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
