Since you only use positive integers and go up to only below 2^32, and intToBits() takes the input as a signed integer, you are short of making it work only by one bit.
One way I could think of was prepending the least significant bit separately to the rest of the 31 bits. (The 32nd bit is always 0, since itβs the sign bit and you only use positive values)
How about replacing the content of your function with something like the following?