Conversion to or from residue codes