Sprite.8Direction.MovingAngle is a value between -180 and 180.
(Sprite.8Direction.MovingAngle + 360) % 360 converts it to a value between 0 and 360
360 / 45 = 8
int(angle / 45) converts an angle between 0 and 360 to a number between 0 and 8
int((Sprite.8Direction.MovingAngle + 360) % 360) / 45
gives you this:
<img src="https://dl.dropbox.com/u/8367729/construct/pics/8dir1.png" border="0" />
Frame 0 would be between 0 and 45 degrees, really you want frame 0 to be between -22.5 and 22.5 so you want to rotate the entire thing 22.5 degrees. That's where the 22.5 comes from:
<img src="https://dl.dropbox.com/u/8367729/construct/pics/8dir2.png" border="0" />