Suppose I have a numpy array of dtype uint16, how do I efficiently manipulate each element of the array so that the bits are reversed?
eg. 0001111010011100 -> 0011100101111000
The existing solutions on this website seem to suggest printing the number into a string which will be really slow for arrays.
Example of what I want to do:
test = np.array([128, 64, 32, 16, 8, 4, 2, 1]).astype(np.uint16)
out = reverse_bits(test)
print(out)
>> array([ 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], dtype=uint16)