The Roman numeral 'L' means 50. If you put an 'X' in front of it, it means -10 + 50 = 40. It seems that the rule is that 'if a numeral is less than the one that follows it, make the first number negative.' Thus, XXXIX is 10+10+10+(-1)+10 = 39. I don't know why you can't just use IIII for 4 and XXXX for 40. I guess the Romans had their reasons.
XXXIX = 10 + 10 + 10 + -1 + 10 = 39
XL = -10 + 50 = 40
XLI = -10 + 50 + 1 = 41
XLII = -10 + 50 + 2 = 42
XLIII = -10 + 50 + 3 = 43
XLIV = -10 + 50 + -1 + 5 = 44
XLV = -10 + 50 + 5 = 45
XLVI = -10 + 50 + 6 = 46
XLVII = -10 + 50 + 7 = 47
XLVIII = -10 + 50 + 8 = 48
XLIX = -10 + 50 + -1 + 10 = 49
L = 50