Generalization of $n$ mod $2 = \dfrac{1-(-1)^n}{2}$ I had this idea that 
$n$ mod $2 = \dfrac{1-(-1)^n}{2}$ for $n \in \mathbb{N}$.
Are there any generalizations for this? For example for $n$ mod $3$ etc.?
I would prefer some answers containing basic arithmetic operations, although the use of analytic functions is also accepted.

To give an alternate approach to Hurkyl's answer. If you let $\zeta$ be a primitive $n$-th root of unity, the function 
$$f_n(x)=\sum_{i=0}^{n-1} i\frac{(\zeta^x-\zeta^0)...(\zeta^x-\zeta^{i-1})(\zeta^x-\zeta^{i+1})...(\zeta^x-\zeta^{n-1})}{(\zeta^i-\zeta^0)...(\zeta^i-\zeta^{i+1})(\zeta^i-\zeta^{i+1})...(\zeta^i-\zeta^{n-1})}.$$
Gives you $f_n(k) = (k\mod n)$, for all integers $k$. 
As an example, if we let $n = 2$ we get
$$f_2(x)=0\frac{(-1)^x-(-1)^1}{(-1)^{0}-(-1)^1}+1\frac{(-1)^x-(-1)^0}{(-1)^1-(-1)^0}=0+\frac{1-(-1)^x}{2}$$
which is identical to the formula you have.
Essentially what we did here is found a polynomial $p_n$, using the Lagrange Interpolation Formula, where $p_n(\zeta^k)=k$ for all $0 \leq k < n$. Then we let $f_n(x)=p_n(\zeta^x)$.
