// simulation using two classical bits // #include void X( int b[], int k) { b[k] = !b[k]; } // NOT on bit k void CX( int b[], int c, int k) // controlled-NOT on bit k controlled by bit c, c != k { b[k] ^= b[c]; // if( b[c]) b[k] = !b[k]; } void print( const char msg[], int b[]) { printf( "%4s:", msg); for( int i = 1; i >= 0; --i) printf( " %i", b[i]); printf( "\n"); } int main( void) { int b[2] = { 0, 0 }; print( "b", b); X(b,1); print( "X", b); CX(b,1,0); print( "CX10", b); } /* output: b: 0 0 X: 1 0 CX10: 1 1 */