Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's not guaranteed to work.

If min+max is a negative signed int, then the result of right shifting is implementation dependent.

Instead, you could do

    int middle = (unsigned)(min + max) >> 1;
Still, this relies on the original indices falling in the non-negative range of signed ints.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: