You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] GrayCodeConversion loses the high bit of 32-bit inputs #7760
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