Expectation of a continuous random variable explained in terms of the CDF Problem:
Let $F_X(x)$ be the CDF of a continuous random variable $X$. Show that:
$$E[X]= \int_0^\infty(1-F_X(x)) \, dx -\int_{-\infty}^0F_X(x) \, dx.$$
Attempt:
A comprehensible explanation of the intuition regarding the expectation $E[X]$ and CDF for a non-negative random is found here: Intuition behind using complementary CDF to compute expectation for nonnegative random variables. 
However, I am still at a loss about how to show the general case when $-\infty < x < \infty$.
I am again solving this as an exercise in my probability course and any help is greatly appreciated!
 A: By integrating by parts
$$\int_0^\infty(1-F_X(x))dx -\int_{-\infty}^0F_X(x)dx=
[x(1-F_X(x))]_0^{+\infty}-\int_0^{+\infty} xd(1-F_X(x)) \\
-[xF_X(x)]_{-\infty}^0+\int_{-\infty}^0xdF_X(x)
=0+\int_0^{+\infty} xdF_X(x)-0+\int_{-\infty}^0 xdF_X\\=\int_{-\infty}^{+\infty} xdF_X(x)=E[X].$$
P.S. Note that by Markov's inequality, if $E[X]$ is finite then $F_X(x)=o(1/x)$ for $x\to-\infty$ and $1-F_X(x)=o(1/x)$ for $x\to+\infty$.
A: You can also see it by interchanging the order of integrals. We have
\begin{eqnarray*}
\int_{0}^{\infty}(1-F_{X}(x))dx=\int_{0}^{\infty}P(X>x)dx & = & \int_{0}^{\infty}\int_{x}^{\infty}dF_{X}(t)dx\\
 & = & \int_{0}^{\infty}\int_{0}^{t}dF_{X}(t)dx\\
 & = & \int_{0}^{\infty}t\;dF_{X}(t)
\end{eqnarray*}
and,
\begin{eqnarray*}
\int_{-\infty}^{0}F_{X}(x)dx=\int_{-\infty}^{0}P(X\leq x)dx & = & \int_{-\infty}^{0}\int_{-\infty}^{x}dF_{X}(t)dx\\
 & = & \int_{-\infty}^{0}\int_{t}^{0}dF_{X}(t)dx\\
 & = & \int_{-\infty}^{0}-t\;dF_{X}(t)
\end{eqnarray*}
Since,
$$
E[X]=\int_{-\infty}^{0}t\;dF_{X}(t)+\int_{0}^{\infty}t\;dF_{X}(t)
$$
the result follows.
A: As far as I understand you can take like this.
$$E(X) = \int_{-\infty}^{\infty}xdF_{X}(x) = \int_{-\infty}^{0}xdF_{X}(x)+ (-\int_{0}^{\infty}xd(1-F_{X}(x))$$
Using integration by part (and having $F(x)$ is always faster than $x$ at the infinities(otherwise the expectation would not exist.) We will have the result.
