Expected number of tosses to get a head from a coin using integration formulae? I recently started learning Expectation Probability , first of all Any Good resources to study it will be appreciated if any one can share 
What I have learnt so far the expected  value of some Unknown Variable say $x$ be $ E(x)$ 
which boils down this equation  $ E(x) = \int_{-\infty}^\infty x*P(x) dx $ where P(x) is the Probability of some specific $x$ . 
So I wanted to find the Expected Number of tosses to Get a  Heads from an Unbiased Coin So I used this equation to solve it 
$E(Getting Heads) =>  \int_{0}^\infty\dfrac{x}{2^x}  dx$ , **IT IS A PRETTY STANDARD RESULT THAT E(GETTING  HEADS) = 2, But this integral is giving me another answer , which is $\dfrac{1}{\ln^2\left(2\right)}$  Can Anyone tell me where am I going wrong with understanding stuff.
 A: The integral formula you're using only applies to continuous random variables with probability density function $p(x)$. But the "number of coin tosses before heads appears" is a discrete random variable because it only takes integer values. The expected value of a discrete random variable is $E(X)=\sum_x x\cdot P(X=x)$, taking the sum over all possible values $x$.
A: 
How will I solve this summation to get an answer 2 ?

From your phrasing of the question, I'm assuming that you threw the coin $n$ times and got tails each time, and then you got heads on the $(n+1)$-th time.  The probability of this occurring is $\frac{1}{2^{n+1}}$.  So you want to find the value of
$$ \frac{1}{2} \sum_{n=0}^\infty \frac{n+1}{2^n} $$
There is a trick for solving this kind of sum, assuming that you already know the sum of a geometric series and some basic calculus.  (If not, there are other ways of proving it, but the only ways I know are conceptually more difficult.)
$$ \begin{align}
\sum_{n=0}^\infty (n + 1) x^n &= \sum_{n=0}^\infty \frac{d}{dx} x^{n+1} \\
&= \frac{d}{dx} \sum_{n=0}^\infty x^{n+1} \\
&= \frac{d}{dx} \frac{x}{1-x} \\
&= \frac{1}{(1-x)^2} \\
\end{align} $$
The second line (moving the derivative outside the sum) is actually nontrivial, but it is okay in this instance because the sum converges uniformly.  (This is a technical detail that may or may not be interesting to you.)  The third line is just summing a geometric series, and the fourth line is basic calculus and some algebra.
Plugging in $x=\frac{1}{2}$ recovers your original problem.  The answer is
$$ \frac{1}{2} \sum_{n=0}^\infty \frac{n + 1}{2^n} = \frac{1}{2} \frac{1}{\left( 1 - \frac{1}{2} \right)^2} = 2 $$
