The formula is $\lceil\log_2 n\rceil$, the symbol $\lceil x\rceil$ meaning "the smallest integer greater or equal to $x$". (Programming languages often have a ceil function.)
This is because, if $m=\lceil\log_2n\rceil$, then $m-1\lt\log_2n\le m$, i.e. $2^{m-1}\lt n\le 2^m$ i.e. $\frac{n}{2^m}\le 1\lt \frac{n}{2^{m-1}}$ which means that $m-1$ halvings isn't enough to bring $n$ to $1$ (or under), but $m$ halvings is.
Update: If your platform does not support $\lceil x\rceil$ but it supports $\lfloor x\rfloor$, with the meaning "the largest integer less or equal than $x$" (often known as the floor function), then recall that $\lceil x\rceil=-\lfloor-x\rfloor$, i.e. the formula becomes $-\lfloor-\log_2 n\rfloor$. Make sure that your implementation of $\lfloor x\rfloor$ works correctly for the negative numbers, e.g. $\lfloor -0.5\rfloor=-1$.