- 2
% operator is used for what actually???
3 Respuestas
+ 6
Hello !!
You can try to search this question on Sololearn Q/A search bar so that you can get varied answers and to avoid duplicates.
You can refer these threads :
https://www.sololearn.com/discuss/2027540/?ref=app
https://www.sololearn.com/discuss/2025684/?ref=app
https://www.sololearn.com/discuss/2022851/?ref=app
+ 2
Atleast % will be very useful when converting number of base x to number of base y.
Example: Convert decimal (10th base) value of 598 to hexadecimal (16th base).
First we would take remainder:
598 % 16 = 6 | 6
Store it and subtract it from the decimal.
598 - 6 = 592
Next we would divide 592 by 16:
592 / 16 = 37
And get to use modulo again annd repeat same tasks until we get 0:
37 % 16 = 5 | 5
37 - 5 = 32
32 / 16 = 2
2 % 16 = 2 | 2
2 - 2 = 0
In the end we'd've got 256, which is the correct result.
+ 1
% used for Remainder
5 % 4=1