Let the number of boys be \( 5x \) and the number of girls be \( 8x \).
After the changes, the number of boys becomes \( 5x - 5 \) and the number of girls becomes \( 8x + 4 \).
The new ratio is \( \frac{5x - 5}{8x + 4} = \frac{1}{2} \).
Solving this, we find \( x = 28 \).
Thus, the original number of boys was \( 5 \times 28 = 140 \), and the original number of girls was \( 8 \times 28 = 224 \).
The difference between the number of boys and girls is \( 224 - 140 = 84 \).
Thus, the difference is 24.