3 ms·
No. An arithmetic shift right does a division that rounds down; an integer division operation instead truncates (rounds to zero). The easiest example is -1 / 2:
by jcranmer 7y ago
No. An arithmetic shift right does a division that rounds down; an integer division operation instead truncates (rounds to zero). The easiest example is -1 / 2: -1 / 2 is 0, but -1 ashr 1 is -1.
To replace a signed division with ashr, you have to know that for all negative inputs, the value of the bits shifted out are all 0.