The IV's are a little tricky.
So the IV block is 32 bits. Let that be an integer. Read that like this:
BitConverter.ToUInt32(binary, offset)
An IV is 5 bits. You grabbed 32 bits. Now to remove the rest.
HP is the easiest to get. In the below, suppose all IVs are 31 except HP. Converting the IV block integer to binary results in this:
11111111111111111111111111100000
You don't necessarily know what the data where the 1's are when finding HP. But you don't need to. You just need to set all of those bits to 0.
Dim HP as Byte = (IVBlock Or &HFFFFFFE0) - &HFFFFFFE0
The above will set all those irrelevant bits to 1 then subtract that number. Something like this:
11111111111111111111111111101010
-11111111111111111111111111100000
---------------------------------
01010 - the value you wanted
And there you go. The HP.
Now for the Attack. A little harder.
In this case, if the attack was all 0, it would be:
11111111111111111111110000011111
How do we solve that? A Bit Shift!
Basically, before you do the Or-ing like above, use: (IVBlock >> 5) Or &H111.. whatever.
The >> is a right shift. It moves all the bits to the right, 5 times. So, it makes 11111111111111111111110000011111 become 11111111111111111111111111100000.
I'm sure you want more than the explanation I gave above, but I wanted you to know what I was doing before I posted some code I conveniently already wrote.