These are the p-values, the probability of being worse off than the data, assuming the null hypothesis is correct.

In the first case, you assume under the null that it's equally likely to see a male or female out of 18 children, so p=.5 under the null.

You observe 12 males, hence the p-value is where n=18 and p=.5

and you double it since this is a two sided test.

vs.

You then compare the p-vale to your alpha in order to make a decision.

In the second one, I'D put the thing I want to prove in the althernative hypothesis.

Hence my alternative is

The null can either be or for simplicity

Both are treated the same.