You can convert a number to mod 8 by repeatedly adding or subtracting 8's until its in that range.
(undoubtably, the actual method of calculation is more sophisticated than this)
Because it is treating -2 as if it is 0xfffffffe (32-bit) (how the computer represents negative numbers) which is 4,294,967,294 and that number divided by 8 equals 536,870,911.75 and 0.75*8 = 6.