Using integer math alone, I\'d like to \"safely\" average two unsigned ints in C++.
What I mean by \"safely\" is avoiding overflows (and anything else that can be th
(((a&b << 1) + (a^b)) >> 1) is also a nice way.
(((a&b << 1) + (a^b)) >> 1)
Courtesy: http://www.ragestorm.net/blogs/?p=29