In a given compound that contains three elements (e.g. a metal, a non-metal, and hydrogen), how can it be determined whether hydrogen is connected to the metal or the non-metal so that its oxidation number can be assigned accordingly?
You can look at the electronegativity of the atom Hydrogen is bonded too.
For instance, in NaH the electronegativity of H is greater than that of Na (~2.1 as opposed ~.9) so H two would have an oxidation state of -1)
In HCl, we observe that Cl is more electronegative so it will have an oxidation state of -1 and H will have an oxidation state of +1
In borane (even though B is a non-metal) each hydrogen displays an oxidation state of -1 (again electronegativity of H is 2.1 as opposed 2.0 of B)
Hope this makes sense.