Skip to content

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

Open

Description

@naveenkumar982

GrayCodeConversion loses the high bit when encoding a 32-bit Java int and skips the decoding loop when that bit is set. This makes two different input bit patterns, 0x00000000 and 0xFFFFFFFF, encode as zero.

Reproduced on e79b0f1:

Call Actual Expected
binaryToGray(0xFFFFFFFF) 0x00000000 0x80000000
grayToBinary(0x80000000) 0x80000000 0xFFFFFFFF

In reflected binary Gray code, the most significant bit is copied from the input. For an input of all ones, every adjacent pair of bits is equal, so all the lower Gray bits are zero. Decoding that bit pattern should recover the original 32 bits.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions