If you are asking about the equality $$E_p\left[\log_2 \frac1{p_x}\right] = -\sum_x p_x\log_2 p_x$$ then it is just the definition of expected value and using $\log_2\frac1x=-\log_2x$. (Which, of course, works for logarithms at any base, not just base two.)