# Calculating of expectation

I've found this formula in a blog, it is in the answer to one question. But I don't know how to prove this:

Let $x_n$ be a sum of $n$ i.i.d. Bernoulli random variables with parameter $1/2$. Let $q\geq 2$. Show that $$E((2x_n-n)^q)=\sum_{k=0}^n{n \choose k}2^{-n}(2k-n)^q$$

That does not make sense. I guess you mean $x_n$ is the sum of $n$ Bernoulli variables? – leonbloy May 5 '12 at 15:14
Let $X$ be a random variable that, for simplicity, can only take on the values $x_0,x_1,\dots,x_n$. Suppose moreover that $P(X=x_k)=p_k$. Let $f$ be any real-valued function defined at least on the $x_k$. Then it is a standard fact that $$E(f(X))=\sum_{k=0}^n f(x_k)p_k.$$ The result quoted is a special case of this, with $x_k=k$, and $X$ having binomial distribution with $p=1/2$, and $f(x)=(2x-n)^q$.