# 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$$

Thank you for your help.

-
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
You are right. It was typo. Thank you –  Michael May 5 '12 at 15:39
Michael: Why not asking directly this question there? To call MSE a blog is a bit deceptive, wouldn't you say? –  Did Jun 5 '12 at 15:39
@dif: I am very dorry. I've had an experience when I' ve asked question in the comment and someone told me that I have to ask questions separately... Si, this time I' ve asked separate question. Sorry for my mistake. It would not happened again. –  Michael Jun 5 '12 at 18:02
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$.