I use a struct to represent the direction like this:
Your question is actually what is the algorithm for a vector cross-product.
F.x = (B.y * I.z) - (B.z * I.y);
F.y = (B.z * I.x) - (B.x * I.z);
F.z = (B.x * I.y) - (B.y * I.x);