 # {Solved}Modulus

I am still very vague as how modulus works in a program, i have read the reference & wiki, but it hasn’t sunk in.

I have no code, but here is something ish.

``````int counter = 0;
int overflow = 0;

void setup(){ }

void loop()
{
if counter >= 32767 ?? // mod % 200, add the remainder back into counter, take 32600 divide by 200 & add to overflow
if counter <= -32767 // mod % 200, add the remainder back into counter, take -32600 divide by 200 & add to overflow

dosomething();
counter = counter++;

or

dosomethingelse();
counter = counter--;
``````

That’s roughly what i was thinking of doing, somehow?

I don't really understand your question, but the modulus is just the remainder after a division.

eg.

``````11 % 6 --> 5
``````

That is, if you divide 11 by 6 you get 1 with 5 remainder.

Also for me is not clear what do you want to do. Sorry.

Modulus give you remainder of division. Usually I used this operator to split the single numbers of a value.

``````int val=456;
int n1=val % 10;  // n1=6
val=val/10;
int n2=val%10; // n2=5
val=val/10;
int n3=val%10; // n3=4
``````

Something like this. But is not the best code, you can use a loop like for or while.

11 % 6 --> 5

How do you store the 1 & the remainder 5 ?

counter = 32767 remainder = counter % 200 // remainder = 167 overflow = (counter - remainder) / 200 counter = remainder

i think is right?

you can use only a division: overflow=counter/200;

if every variable are integer like int or long you bring only integer part in overflow variable or you can force using cast overflow=(int)counter/200;

Thanks, that cleared it up for me XD