-
-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Description
Repository commit
Python version (python --version)
Python 3.12.8
Dependencies version (pip freeze)
Summery
The reverse_bits function added in PR #4120 appears to return the original number’s binary string instead of its 32-bit bit-reversed form.
Example:
When input is 5, the correct 32-bit reversed output should be:
Input (decimal): 5
Expected output: 10100000000000000000000000000000
Actual output: 00000000000000000000000000000101
This behavior occurs because the reverse_bits
function calls get_reverse_bit_string
with the already bit-reversed
decimal result. Inside get_reverse_bit_string
, the number is reversed again, effectively undoing the original reversal. As a result, the final output is incorrect.
Proposed Solution
The fix is to stop calling get_reverse_bit_string() inside reverse_bits() and instead return the reversed decimal value directly. Since get_reverse_bit_string() already handles string formatting, reverse_bits() should now strictly deal with returning the integer result of the bit reversal.
Expected behavior
Input: 5
Expected 32-bit binary: 00000000000000000000000000000101
Expected reversed: 10100000000000000000000000000000
Expected decimal: 2684354560
Actual behavior
Input: 5
Actual : 00000000000000000000000000000101