Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Binary-to-Gray and Gray-to-Binary Conversion Functions #4524

Closed
SanketPatil7467 opened this issue Oct 1, 2023 · 1 comment
Closed

Comments

@SanketPatil7467
Copy link

What would you like to Propose?

Binary to Gray Conversion and Gray to Binary Conversion

I propose adding new functions to this project that will allow for binary-to-gray and gray-to-binary conversions. These conversions are essential in various digital communication and signal processing applications. The functions should handle efficient and accurate conversion between binary and Gray code representations, contributing to the versatility and usefulness of the project.

Issue details

Logic to convert Binary to Gray code & Gray to Binary code

1.Binary to Gray:

Here the most significant bit of the gray code is same as the given binary code so we don't need to make any changes. Further traversing the binary from 1st index (i.e 2nd position) we take the xor of current index character of binary code with the previous index character of binary code and add it to our converted gray code.

  1. Gray to Binary:

Here the most significant bit of the Binary code is same as the given Gray code, so we direclty copy it. Further traversing the Gray code we check if the current character of Gray code is '0', if it is '0' we copy the value of previous index of converted Binary code, else we copy the flipped value of current Gray character to our binary code.

Additional Information

No response

@SanketPatil7467
Copy link
Author

@yanglbme, @debasishbsws, @vil02 , @BamaCharanChhandogi In pull request #4525 solution of this binary to gray and gray to binary is mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant