In case of unsigned integer u
, we can easily get quotient with u>>k
(k means divide by 2^k)
But in case of negative numbers, it should be computed as (u+(1<<k)-1)>>k
I can see that u>>k
does not work for negative numbers.
But I am curious why we exactly have to add (1<<k)-1
to u
Any explanations might really be helpful.