Skip to content

Preserve the high bit in 32-bit Gray code conversion - #7761

Open
naveenkumar982 wants to merge 1 commit into
TheAlgorithms:masterfrom
naveenkumar982:codex/gray-code-32-bit
Open

naveenkumar982 wants to merge 1 commit into
TheAlgorithms:masterfrom
naveenkumar982:codex/gray-code-32-bit

Conversation

@naveenkumar982

Copy link
Copy Markdown

Closes #7760.

Use unsigned right shifts so the 32-bit reflected Gray code keeps its most significant bit. Decoding now continues until every bit has shifted out, including when the Gray word has its high bit set.

Two regression tests check encoding and decoding against known patterns. Both tests failed on the base revision. A separate deterministic check on 100,000 32-bit inputs verified that decoding recovers the input and that consecutive inputs have Gray codes differing by one bit.

I used OpenAI Codex to help prepare and test this change. The two changed Java files were formatted with the repository's clang-format configuration.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.42%. Comparing base (e79b0f1) to head (c1a1913).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7761   +/-   ##
=========================================
  Coverage     82.42%   82.42%           
  Complexity     8508     8508           
=========================================
  Files           847      847           
  Lines         26289    26289           
  Branches       5133     5133           
=========================================
  Hits          21670    21670           
  Misses         3828     3828           
  Partials        791      791           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@naveenkumar982
naveenkumar982 marked this pull request as ready for review November 18, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] GrayCodeConversion loses the high bit of 32-bit inputs

2 participants