  We show that the equations of motion for (free) integer higher spin gauge
fields can be formulated as twisted self-duality conditions on the higher spin
curvatures of the spin-$s$ field and its dual. We focus on the case of four
spacetime dimensions, but formulate our results in a manner applicable to
higher spacetime dimensions. The twisted self-duality conditions are redundant
and we exhibit a non-redundant subset of conditions, which have the remarkable
property to involve only first-order derivatives with respect to time. This
non-redundant subset equates the electric field of the spin-$s$ field (which we
define) to the magnetic field of its dual (which we also define), and vice
versa. The non-redundant subset of twisted self-duality conditions involve the
purely spatial components of the spin-$s$ field and its dual, and also the
components of the fields with one zero index. One can get rid of these gauge
components by taking the curl of the equations, which does not change their
physical content. In this form, the twisted self-duality conditions can be
derived from a variational principle that involves prepotentials, which are the
higher spin generalizations of the prepotentials previously found in the spins
2 and 3 cases. The prepotentials have again the intriguing feature of
possessing both higher spin diffeomorphism invariance and higher spin conformal
geometry. The tools introduced in an earlier paper for handling higher spin
conformal geometry turn out to be crucial for streamlining the analysis. In
four spacetime dimensions where the electric and magnetic fields are tensor
fields of the same type, the twisted self-duality conditions enjoy an $SO(2)$
electric-magnetic invariance. We explicitly show that this symmetry is an
"off-shell symmetry" (i.e., a symmetry of the action and not just of the
equations of motion). Remarks on the extension to higher dimensions are given.
