Anything that mentions Jon Bentley is worth pointing to.
“In Programming Pearls Bentley says that the analogous line “sets
m to the average of l and u, truncated down to the nearest integer.” On
the face of it, this assertion might appear correct, but it fails for
large values of the int variables low and high. Specifically, it fails if the sum of low and high is greater than the maximum positive int value (231
- 1). The sum overflows to a negative value, and the value stays
negative when divided by two. In C this causes an array index out of
bounds with unpredictable results. In Java, it throws ArrayIndexOutOfBoundsException.”
Tim Bray was on this very topic too, here and here.
If someone ever asks you why does this computer thing have to be so complicated, review this little piece of math niceness with them. I find that encapsulates in a nice single story the simplicity of a mathematic idea with the complexity of a complete solution. Of course once you mention the words math and binary in the same sentence you’ve probably lost 95% of your audience.
Posted by Paul Marsh