Can't you just do the conversions directly by the use of lookup tables?