In your current approach your are manipulating the array in-place.
This could mess up your indices, since new_IDX could point to an already manipulated index.
Also, are the loops supposed to iterate to 64?