Convert for loop into math sigma notation
Let me define
$$f(x) = \begin{cases} 0 &amp; x \ne 0 \\
 1 &amp; x = 0\end{cases}$$
Now it is
$$ \sum _{i=0}^{{N\over2}+1}\:f(N \text { mod } 2^i)$$
The code calculates how many times number is divisible by two (which by the way could be simplified to checking number of trailing zeros in binary representation, say hacky method x &amp; -x).

You can define {N, 2} for the highest power of a prime 2 that divides N, and it is the valid notation. There are other approaches and notations of greatest power of two dividing N at MathOverflow.