Code simplification - Modulus function

I'm trying to port my code to a different platform:

void displayNumber(int toDisplay) 
{
  for(int digit = 4 ; digit > 0 ; digit--) 
  {
  //Turn on a digit for a short amount of time
  switch(digit) 
    {
    case 1:
      control &= ~_BV(0); // CHIP SELECT - DSPIC DATA, SPI
      break;
    case 2:
      control &= ~_BV(1);
      break;
    case 3:
      control &= ~_BV(2);
      break;
    case 4:
      control &= ~_BV(3);
    break;
    }
  //Turn on the right segments for this digit
  lightNumber(toDisplay % 10);
  toDisplay /= 10;
  //Turn off all segments
   lightNumber(10); 
  control = 0b00001111;  // Represents which digits to light up. For one display the first 4 bits are used.
  }
}

I'm having problems with this part of the loop

 lightNumber(toDisplay % 10);

More specifically the modulus function on the line above.

Any way to implement this function manually?

Also what does this line do, exactly?

toDisplay /= 10;

Thanks

and the rest of the code is ....... ?

UKHeliBob:
and the rest of the code is ....... ?

The code works fine as is, I simply want to know what toDisplay /= 10; means (never seen that operator before) and how to implement modulus manually.

Modulus is remainder.

So you get this: (a/b)*b + a%b = a

so if you do a - (a/b) the remainder should be left. whatever you are porting to might have a mod() or rem() function, same thing.

/= is the the same idea as +=, a/=b => a = a/b

It is on the reference page. Also any of the online C references.

You wrote "I'm trying to port my code to a different platform". So how is anybody supposed to answer "Any way to implement this function manually?" when "this function" refers to an operator (NOT a function!) that is built into C and C++?

If toDisplay is an integer, many languages will allow you to emulate the modulus function by doing the following:

toDisplay - (10*(toDisplay/10))

However, there are some languages where this doesn't work, and it will not work if toDisplay is a real or floating point variable. You have not provided sufficient information to answer the question.

toDisplay /= 10;

is equivalent to

toDisplay = toDisplay/10;

except in some weird corner cases that depend upon the type of toDisplay.

In general english "function" means facility or feature, which is what I took it as.

Thanks, last thing that crossed my mind was division lol

There is an error in my remainder function
You need a - (a/b)*b for the remainder

when "this function" refers to an operator (NOT a function!) that is built into C and C++?

Do you have a clue about how operators are defined/implemented? I didn't think so.

I almost said something like this, but some operators might be translated directly into machine language and not implemented as functions.

KeithRB:
I almost said something like this, but some operators might be translated directly into machine language and not implemented as functions.

Most operators.

I was being cautious, especially since we are talking about %. But I do know that the C statement parser I used for a graphics program basically made every operator/function a function.