Skip to content

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

Merged
DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
naveenkumar982:codex/gray-code-32-bit
Nov 20, 2026
Merged

DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
naveenkumar982:codex/gray-code-32-bit

Conversation

@naveenkumar982

Copy link
Copy Markdown
Contributor

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

codecov-commenter commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.44%. Comparing base (e79b0f1) to head (e71085b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7761      +/-   ##
============================================
+ Coverage     82.42%   82.44%   +0.01%     
- Complexity     8508     8509       +1     
============================================
  Files           847      847              
  Lines         26289    26291       +2     
  Branches       5133     5134       +1     
============================================
+ Hits          21670    21675       +5     
+ Misses         3828     3825       -3     
  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

@DenizAltunkapan DenizAltunkapan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@DenizAltunkapan
DenizAltunkapan enabled auto-merge (squash) November 20, 2026 19:10
@DenizAltunkapan
DenizAltunkapan merged commit f4d6708 into TheAlgorithms:master Nov 20, 2026
13 checks passed
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

3 participants