How do you plan to solve it?
Gray code can be generated by XORing the binary value with itself shifted right by one bit.
This produces the required pattern where each successive value changes only one bit.
Using the expression bin_in ^ (bin_in >> 1) avoids writing each bit manually.
It results in a cleaner, shorter, and scalable implementation.