Updated to make hex digit conversion more efficient.