in generation II, Hidden Power typing is determined by the Attack and Defense IV amounts.

Here's the formula for Gen II IVs:

Where a is the attack IV and b is the defense IV.

Depending on your answer, you will get a different Hidden Power:

>0 Fighting

1 Flying

2 Poison

3 Ground

4 Rock

5 Bug

6 Ghost

7 Steel

8 Fire

9 Water

10 Grass

11 Electric

12 Psychic

13 Ice

14 Dragon

15 Dark

Make sure that when you're finished calculating, you floor, or round down the final answer.

In generations III and onward, the formula to calculate Hidden Power typing is this:

Where a is the HP IV's lease significant bit (lsb), b is the attack IV's lsb, c is the defense IV's lsb, d is the special attack IV's lsb, e is the special defense IV's lsb, and f is the speed IV's lsb.

The lsb is basically the last digit of the value's binary code form. So even numbers would have 1 as an lsb, and odd numbers would have 0 as an lsb.

The same values are corresponded to the same solutions as in generation II, so see the list above to see what hidden power each number indicates. If you notice, there's no value for fairy type hidden power, so fairy type hidden power doesn't exist.

Also, like before, make sure to floor your answers.

Hope I helped!

Source