I am using this simple snippet of code, variants of which I have seen in many places:
for(int k = 0 ; n % 2 == 0 ; k++) n = n / 2;
This code repeatedly divides num
by 2 until it is odd and on completion k
contains the number of divisions performed.
I am wondering what the appropriate way to write this using mathematical notation is? Does this correspond to some named concept?
Of course, $lg\ n$ gives the appropriate $k$ when $n$ is a power of 2, but not for anything else. For example, $k = 1$ when $n = 6$ and $k = 0$ when $n$ is odd. So it looks it should be specified using a piece-wise function but there may be some mathematical concept or nomenclature here that I am not aware of...