What is the simplest way to calculate the amount of even numbers in a range of unsigned integers?
An example: if range is [0...4] then the answer is 3 (0,2,4)
I\
I'd say
(max - min + 1 + (min % 2)) / 2
Edit: Erm okay for some reason I thought that (min % 2) returns 1 for even numbers.... :). The correct version is
(max - min + 1 + 1 - (min % 2)) / 2
or rather
(max - min + 2 - (min % 2)) / 2