0

pLZzz! Modules operation....

Hey! I've problem, which is that: How can I solve this..... 2%-8; I know that modules operation but problem is when the left operand is positive and right operand is negative and left-right reverse then how can I solve problem by manually? *pLZzz*

1st Oct 2017, 12:58 PM
Muhammad Belal
Muhammad Belal - avatar
10 Respuestas
+ 9
2 % 8 = 2 because 2 / 8 is 0+2r 2 % -8 = -6 because 2 / -8 is 0-6r and so on...
1st Oct 2017, 3:42 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 8
Different languages might have this differently resolved. In Python: 2 % 8 = 2 2 % -8 = -6 -2 % 8 = 6 -2 % -8 = -2
1st Oct 2017, 1:42 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
You can not "shorten" this. It is not the division operator - it returns the *remainder* of the division. If you divide the two numbers of the division, surely the remainder will be different. But that will be a totally new operation.
1st Oct 2017, 3:36 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
I assume that you were expected an answer of 2? When I run this in python I get -6. This is fine because 2 and -6 are the same in mod8.
1st Oct 2017, 1:45 PM
Mark McGhee
Mark McGhee - avatar
+ 1
I don't think I was very clear. 2 is equal to -6 in mod8. Try both 2%8 and -6%8 in python and you will see that both output 2. This is because both 2 and -6 are 2 greater than a multiple of 8.
1st Oct 2017, 3:37 PM
Mark McGhee
Mark McGhee - avatar
+ 1
r is the remainder which is what modulus function returns
1st Oct 2017, 3:47 PM
Mark McGhee
Mark McGhee - avatar
0
2% -8; 2 /-8=-6; which is true for modulo: if I short this 1/-4=-3; which is true for modulo. then why the answer is 2. Is here other method for modules...
1st Oct 2017, 3:27 PM
Muhammad Belal
Muhammad Belal - avatar
0
-6 is I get by manually but 2 how can I get this answer by manually
1st Oct 2017, 3:40 PM
Muhammad Belal
Muhammad Belal - avatar
0
here 'r' is what?
1st Oct 2017, 3:44 PM
Muhammad Belal
Muhammad Belal - avatar
0
what means 0+2r and 0-6r. Plzz I'm very suspect, explain.
1st Oct 2017, 3:45 PM
Muhammad Belal
Muhammad Belal - avatar