By definition, oxidation number is the charge left on the central atom when all its bonds are (conceptually) cleaved with the charge going to the most electronegative atom. So let's cleave the I-I bond:
I-I rarr 2I* . We get two iodine atoms, two neutral iodine radicals, 2xxI*. Since there is no charge, the oxidation number is a big fat 0. On the other hand, when we do the same operation with the interhalogen I-Cl, the charge goes to the more electronegative atom, Cl:
I-Cl rarr I^+ + Cl^-. To give formal oxidation states of I^+ of iodine in the molecule, and I^- for chlorine (note these are Roman numerals). The same oxidation states would pertain for Br-Cl, as chlorine is more electronegative than bromine. What are the oxidation numbers of fluorine and oxygen in OF_2? Please report back the answers here.