Moved all conversions to 18 bits into one function.