Heads Up, Heads Down

You are blindfolded and on the table in front of you 50 coins are placed. You are told that X of them are heads up and the rest are heads down. Then you are asked to separate the coins in two groups and optionally flip some of them, so that the number of heads in both groups become the same. How can you do this?

Separate the coins in one group of X coins and in another group of 50-X coins, then flip every coin in the first group. If in the first group there were Y heads up initially, then after flipping there will be X-Y - exactly the number of heads up in the second group.