We present a general method which expresses a unitary operator by the product of operators allowed by the Hamiltonian of spin-1/2 systems. In this method, the generator of an operator is found first, and then the generator is expanded by the base operators of the product operator formalism. Finally, the base operators disallowed by the Hamiltonian, including more than two-body interaction operators, are replaced by allowed ones by the axes transformation and coupling order reduction technique. This method directly provides pulse sequences for the nuclear magnetic resonance quantum computer, and can be generally applied to other systems.