If 0.0418 grams of Mg are reacted with excess HCl, how many moles of hydrogen gas will be formed?

Write the equation.

Balance it.
Convert g Mg to mols. mols = grams/molar mass.
Using the coefficients in the balanced equation, convert mols Mg to mols H2.