Take 1 L of solution. Density gives its mass, the mass percent gives the solute's mass, and the molar mass turns that into moles. Moles per litre is the molarity.
Dividing by the mass of water instead of the volume of solution. That gives molality, not molarity.
with in g mL: .