mod

Kinda silly question why is -2 mod 8 = 6??
can anyone explain me plz :)
A number mod 8 is always in the range 0..7

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)

This is a mathematical definition.
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.

That is where the 6 is coming from.
Last edited on
Topic archived. No new replies allowed.