A method of measuring and correcting errors within a circuit quantum electrodynamics system that includes a physical qubit dispersively coupled to cavity resonator, wherein the cavity resonator has been previously configured with a state that is a superposition of a pair of codewords | W ↑ 〉 and | W ↓ 〉 selected from a class of binomial codes, wherein the pair of codewords | W ↑ 〉 and | W ↓ 〉 encode the state of the physical qubit in the state of the cavity resonator, and wherein the class of binomial codes is expressed by: | W ↑ / ↓ 〉 = 1 2 M ∑ p even / odd M + 1 M + 1 p | p S + 1 〉 in which S and M are integers and |n〉 denotes a photon number state with n photons, the method comprising: measuring a parity of a first state of the cavity resonator, wherein the first state is a superposition of a plurality of photon number states, and wherein measuring the parity of the first state comprises measuring the photon number parity modulo N, where N is an integer greater than or equal to 2; subsequent to measuring the parity of the first state, measuring a parity of a second state of the cavity resonator, the second state being different from the first state, in order to detect an error syndrome of the cavity resonator, the error syndrome indicating that an error has occurred, wherein the error syndrome is associated with a superposition of a pair of error words, and wherein measuring the parity of the second state comprises measuring the photon number modulo N; applying a first drive waveform to the cavity resonator; and applying a second drive waveform to the physical qubit concurrent with the application of the first drive waveform, wherein the first drive waveform and the second drive waveform are selected to correct the error indicated by the error syndrome by performing a unitary state transfer between the pair of codewords and the pair of error words, and wherein application of the first drive waveform and the second drive waveform cause said transitioning of the cavity resonator from the second state back to the first state. measuring a parity of a first state of the cavity resonator, wherein the first state is a superposition of a plurality of photon number states, and wherein measuring the parity of the first state comprises measuring the photon number parity modulo N, where N is an integer greater than or equal to 2; subsequent to measuring the parity of the first state, measuring a parity of a second state of the cavity resonator, the second state being different from the first state, in order to detect an error syndrome of the cavity resonator, the error syndrome indicating that an error has occurred, wherein the error syndrome is associated with a superposition of a pair of error words, and wherein measuring the parity of the second state comprises measuring the photon number modulo N; applying a first drive waveform to the cavity resonator; and applying a second drive waveform to the physical qubit concurrent with the application of the first drive waveform, wherein the first drive waveform and the second drive waveform are selected to correct the error indicated by the error syndrome by performing a unitary state transfer between the pair of codewords and the pair of error words, and wherein application of the first drive waveform and the second drive waveform cause said transitioning of the cavity resonator from the second state back to the first state.