You probably learned early on in science classes that density is mass divided by volume, or the "amount" of a substance in a certain space. For solids, this is a pretty straightforward measure. If you fill a jar full of pennies, it would have a lot more "oomph" than if you filled it with marshmallows. There's a lot more substance packed into the jar when you fill it with pennies, whereas marshmallows are very puffy and light.
How about molecular weight? Molecular weight and density seem extremely similar, but there's an important difference. Molecular weight is a substance's mass per mole. It's not about how much space the substance takes up, but the "amount," the "oomph" or the "heft" of a certain amount of a substance.
TL;DR (Too Long; Didn't Read)
Convert a gas' molecular weight to density using a variation of the Ideal Gas Law:
PV = (m/M)RT,
where P stands for pressure, V stands for volume, m is mass, M is molecular weight, R is the gas constant, and T is temperature.
Then solve for mass over volume, which is density!
So, to recap: Density is mass divided by volume. The mathematical formula looks like this:
ρ = m ÷ V
The SI unit for mass is kilograms (although you may occasionally see it expressed in grams), and for volume it's typically m3. So density in SI units is measured in kg/m3.
Molecular weight is mass per mole, which is written:
molecular weight = m ÷ n.
Again, units matter: Mass, m, will probably be in kilograms, and n is a measurement of the number moles. So the units for molecular weight will be kilograms/mole.
The Ideal Gas Law
So how do you convert back and forth between these measures? To convert a gas' molecular weight to density (or vice versa), use the Ideal Gas Law. The Ideal Gas Law defines the relationship between the pressure, volume, temperature and moles of a gas. It's written:
PV = nRT,
where P stands for pressure, V stands for volume, n is the number of moles, R is a constant that depends on the gas (and is usually given to you), and T is the temperature.
Use the Ideal Gas Law to Convert Molecular Weight to Density
But the Ideal Gas Law doesn't mention molecular weight! However, if you rewrite n, the number of moles, in slightly different terms, you can set yourself up for success.
Check this out:
mass ÷ molecular weight = mass ÷ (mass ÷ moles) = moles.
So moles is the same as mass divided by molecular weight.
n = m ÷ molecular weight
With that knowledge, you can rewrite the Ideal Gas Law like this:
PV = (m÷M)RT,
where M stands for molecular weight.
Once you have that, solving for density becomes simple. Density equals mass over volume, so you want to get mass over volume on one side of the equals sign and everything else on the other side.
So, PV = (m÷M)RT becomes:
PV÷RT = (m÷M) when you divide both sides by RT.
Then multiply both sides by M:
PVM÷RT = m
...and divide by volume.
PM÷RT = m÷V.
m÷V equals density, so
ρ = PM ÷ RT.
Try an Example
Find the density of carbon dioxide (CO2) gas when the gas is at 300 Kelvin and 200,000 pascals of pressure. The molecular weight of CO2 gas is 0.044 kg/mole, and its gas constant is 8.3145 J/mole Kelvin.
You can start with the Ideal Gas Law, PV=nRT, and derive for density from there like you saw above (the advantage of that is that you only have to memorize one equation). Or, you can start with the derived equation and write:
ρ = PM ÷ RT.
ρ = ((200,000 pa) x (0.044 kg/mole)) ÷ (8.3145 J / (mole x K) x 300 K)
ρ = 8800 pa x kg / mole ÷ 2492.35 J / mole
ρ = 8800 pa x kg / mole x 1 mole / 2492.35 J
Moles will cancel out at this point, and it's important to note that pascals and Joules both have some components in common. Pascals are Newtons divided by square meters, and a Joule is one Newton times one meter. So pascals divided by joules gives 1 / m3, which is a good sign because m3 is the unit for density!
ρ = 8800 pa x kg / mole x 1 mole / 2492.35 J becomes
ρ = 8800 kg / 2492.34 m3,
which equals 3.53 kg/m3.
Phew! Well done.