## Reference.Modulo History

June 02, 2010, at 10:30 PM by Equipo Traduccion -
Changed lines 49-50 from:
to:
June 02, 2010, at 10:30 PM by Equipo Traduccion -
Changed lines 1-25 from:

## % (modulo)

#### Description

Calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array).

#### Syntax

result = dividend % divisor

#### Parameters

dividend: the number to be divided

divisor: the number to divide by

the remainder

#### Examples

[@x = 7 % 5; // x now contains 2 x = 9 % 5; // x now contains 4 x = 5 % 5; // x now contains 0 x = 4 % 5; // x now contains 4

to:

## % (módulo)

#### Descrición

Calcula el resto de la división entre dos enteros. Es útil para mantener una variable dentro de un rango particular (por ejemplo el tamaño de un array)

#### Parametros

dividendo: el número que se va a dividir

divisor: el número por el que se va a dividir

#### Devuelve

el resto de la división

#### Ejemplo

[@x = 7 % 5; // x ahora contiene 2 x = 9 % 5; // x ahora contiene 4 x = 5 % 5; // x ahora contiene 0 x = 4 % 5; // x ahora contiene 4

Changed line 28 from:

to:

#### Código de ejemplo

Changed lines 30-32 from:

/* update one value in an array each time through a loop */

int values[10];

to:

/* actualiza un valor en el array cada vez que se pasa por el bucle */

int valores[10];

Changed lines 39-40 from:
```  values[i] = analogRead(0);
i = (i + 1) % 10;   // modulo operator rolls over variable
```
to:
```  valores[i] = analogRead(0);
i = (i + 1) % 10;   // el operador módulo prevalece sobre la variable
```
Changed lines 44-48 from:

#### Tip

The modulo operator does not work on floats.

to:

#### Nota

El operador modulo no funciona con datos en coma flotante (float)

#### Véase también

December 22, 2008, at 02:56 PM by Paul Badger -
Changed lines 30-31 from:
• / update one value in an array each time through a loop */
to:

/* update one value in an array each time through a loop */

December 22, 2008, at 02:55 PM by Paul Badger -
• / update one value in an array each time through a loop */
Changed line 40 from:
```  i = (i + 1) % 10;
```
to:
```  i = (i + 1) % 10;   // modulo operator rolls over variable
```
October 11, 2008, at 11:18 PM by David A. Mellis -
Changed lines 5-6 from:

Returns the remainder from an integer division

to:

Calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array).

Changed lines 9-10 from:

result = value1 % value2

to:

result = dividend % divisor

Changed lines 13-16 from:

value1: a byte, char, int, or long

value2: a byte, char, int, or long

to:

dividend: the number to be divided

divisor: the number to divide by

Changed lines 19-20 from:

The remainder from an integer division.

to:

the remainder

Deleted lines 27-28:

The modulo operator is useful for tasks such as making an event occur at regular periods or making a memory array roll over

Changed lines 30-36 from:

// check a sensor every 10 times through a loop void loop(){ i++; if ((i % 10) == 0){ // read sensor every ten times through loop

```   x = analogRead(sensPin);
}
```

/ ...

to:

int values[10]; int i = 0;

void setup() {}

void loop() {

```  values[i] = analogRead(0);
i = (i + 1) % 10;
```
Deleted lines 39-55:

// setup a buffer that averages the last five samples of a sensor

int senVal[5]; // create an array for sensor data int i, j; // counter variables long average; // variable to store average ...

void loop(){ // input sensor data into oldest memory slot i = i % 5; // modulo operator resets i to 0 when i = 4 sensVal[i] = analogRead(sensPin); average = 0; for (j=0; j<5; j++){ average += sensVal[j]; // add up the samples } average = average / 5; // divide by total

Deleted lines 41-52:

The modulo operator can also be used to strip off the high bits of a variable. The example below is from the Firmata library.

```    // send the analog input information (0 - 1023)
Serial.print(value % 128, BYTE); // send lowest 7 bits
Serial.print(value >> 7, BYTE);  // send highest three bits
```

Changed lines 43-44 from:

the modulo operator will not work on floats

to:

The modulo operator does not work on floats.

Changed lines 47-49 from:
to:
September 26, 2008, at 04:02 PM by Paul Badger -
Changed lines 49-50 from:

to:

i = i % 5; // modulo operator resets i to 0 when i = 4 sensVal[i] = analogRead(sensPin);

March 25, 2008, at 09:13 PM by Paul Badger -
March 25, 2008, at 09:11 PM by Paul Badger -
Changed line 60 from:

to:

Changed lines 62-68 from:
```     Serial.print(value >> 7, BYTE);  // send highest three bits  ]]
```

to:
```     Serial.print(value >> 7, BYTE);  // send highest three bits  @]
```

March 25, 2008, at 09:11 PM by Paul Badger -
Changed lines 59-60 from:

[[

```     // send the analog input information (0 - 1023)
```
to:

Changed lines 62-68 from:
```     Serial.print(value >> 7, BYTE);  // send highest three bits
```

]]

to:
```     Serial.print(value >> 7, BYTE);  // send highest three bits  ]]
```

March 25, 2008, at 09:10 PM by Paul Badger -
Changed lines 57-58 from:

The modulo operator can also be used to strip off the high bytes of a variable. The example below is from the Firmata library.

to:

The modulo operator can also be used to strip off the high bits of a variable. The example below is from the Firmata library.

Changed lines 60-61 from:

```     Serial.print(value % 128, BYTE); //send lowest 7 bits
```
to:
```     // send the analog input information (0 - 1023)
Serial.print(value % 128, BYTE); // send lowest 7 bits
```
March 25, 2008, at 09:09 PM by Paul Badger -
Changed lines 57-58 from:
to:

The modulo operator can also be used to strip off the high bytes of a variable. The example below is from the Firmata library.

```     Serial.print(value % 128, BYTE); //send lowest 7 bits
Serial.print(value >> 7, BYTE);  // send highest three bits
```

]]

July 16, 2007, at 11:55 AM by Paul Badger -
Changed line 34 from:

if ((i % 10) == 0){ // read sensor every ten times through loop

to:

if ((i % 10) == 0){ // read sensor every ten times through loop

July 16, 2007, at 11:54 AM by Paul Badger -
Changed lines 34-35 from:

if ((i % 10) == 0){

```   x = analogRead(sensPin);   // read sensor every ten times through loop
```
to:

if ((i % 10) == 0){ // read sensor every ten times through loop

```   x = analogRead(sensPin);
```
May 29, 2007, at 03:12 AM by Paul Badger -
Changed lines 65-66 from:
to:
May 29, 2007, at 03:12 AM by Paul Badger -
Changed lines 65-66 from:
to:
May 29, 2007, at 03:11 AM by Paul Badger -
Changed lines 65-66 from:
to:
May 29, 2007, at 03:11 AM by Paul Badger -
Changed lines 65-66 from:
to:
May 05, 2007, at 02:46 PM by Paul Badger -
Deleted line 39:
May 05, 2007, at 02:45 PM by Paul Badger -
Changed lines 34-35 from:

if ((i % 10) == 0){x = analogRead(sensPin);}

to:

if ((i % 10) == 0){

```   x = analogRead(sensPin);   // read sensor every ten times through loop
}
```

/ ... }

May 05, 2007, at 02:43 PM by Paul Badger -
Changed lines 27-28 from:

The modulo operator is useful for tasks like making an event occur at regular periods or making a memory array roll over

to:

The modulo operator is useful for tasks such as making an event occur at regular periods or making a memory array roll over

April 16, 2007, at 05:54 PM by Paul Badger -
April 16, 2007, at 05:54 PM by Paul Badger -
Deleted lines 61-62:
April 16, 2007, at 05:54 PM by Paul Badger -
Changed lines 27-28 from:

The modulo operator is useful for making an event occur at regular periods and tasks like making a memory array roll over

to:

The modulo operator is useful for tasks like making an event occur at regular periods or making a memory array roll over

April 15, 2007, at 10:57 PM by Paul Badger -
Changed lines 8-9 from:

x % y

to:

result = value1 % value2

Changed lines 12-15 from:

x: a byte, char, int, or long

y: a byte, char, int, or long

to:

value1: a byte, char, int, or long

value2: a byte, char, int, or long

April 15, 2007, at 09:07 PM by Paul Badger -
Deleted line 35:
Deleted lines 54-55:
April 15, 2007, at 09:06 PM by Paul Badger -
Changed line 58 from:

to:

#### Tip

April 14, 2007, at 05:45 AM by Paul Badger -
Changed lines 63-65 from:
to:

April 14, 2007, at 05:43 AM by Paul Badger -
Changed lines 27-28 from:

The modulo operator is useful for making an event occur at regular periods, and tasks like making a memory array roll over

to:

The modulo operator is useful for making an event occur at regular periods and tasks like making a memory array roll over

April 14, 2007, at 05:42 AM by Paul Badger -
Changed lines 6-9 from:
to:

#### Syntax

x % y

Changed lines 12-15 from:

x: the first number, a byte, char, int, or long

y: the second number, a byte, char, int, or long

to:

x: a byte, char, int, or long

y: a byte, char, int, or long

Changed line 21 from:

[@x = 7 % 5; // x now contains 2

to:

[@x = 7 % 5; // x now contains 2

Changed lines 46-47 from:

to:

sensVal[(i++) % 5] = analogRead(sensPin); average = 0;

Changed line 49 from:

average = sensVal[j]; // add up the samples

to:

average += sensVal[j]; // add up the samples

April 14, 2007, at 05:33 AM by Paul Badger -
Changed line 18 from:

[@x = 7 % 5; // x now contains 2

to:

[@x = 7 % 5; // x now contains 2

Changed line 26 from:

to:

#### Example Code

April 14, 2007, at 05:33 AM by Paul Badger -
Changed line 18 from:

[@x = 7 % 5; // x now contains 2

to:

[@x = 7 % 5; // x now contains 2

Changed lines 24-33 from:

The modulo operator is useful for generating repeating patterns or series of numbers, such as getting a memory array to roll over

#### Example Program

[@// setup a buffer that averages the last five samples of a sensor

int senVal[5]; // create an array for sensor data int i, j; // counter variables long average; // variable to store average ...

to:

The modulo operator is useful for making an event occur at regular periods, and tasks like making a memory array roll over

#### Example Programs

[@ // check a sensor every 10 times through a loop

i++; if ((i % 10) == 0){x = analogRead(sensPin);}

// setup a buffer that averages the last five samples of a sensor

int senVal[5]; // create an array for sensor data int i, j; // counter variables long average; // variable to store average ...

void loop(){

April 14, 2007, at 05:25 AM by Paul Badger -
Changed line 18 from:

x = 7 % 5; // x now contains 2

to:

[@x = 7 % 5; // x now contains 2

Changed lines 22-23 from:
to:

@]

Changed lines 27-28 from:

{@// setup a buffer that averages the last five samples of a sensor

to:

[@// setup a buffer that averages the last five samples of a sensor

April 14, 2007, at 05:23 AM by Paul Badger -
Changed lines 26-33 from:

// setup a buffer that averages the last five samples of a sensor

int senVal[5]; //create an array for sensor data

to:

{@// setup a buffer that averages the last five samples of a sensor

int senVal[5]; // create an array for sensor data int i, j; // counter variables long average; // variable to store average ...

void loop(){ // input sensor data into oldest memory slot sensVal[i++ % 5] = analogRead(sensPin); for (j=0; j<5; j++){ average = sensVal[j]; // add up the samples } average = average / 5; // divide by total @]

April 14, 2007, at 05:15 AM by Paul Badger -

## % (modulo)

#### Description

Returns the remainder from an integer division

#### Parameters

x: the first number, a byte, char, int, or long

y: the second number, a byte, char, int, or long

#### Returns

The remainder from an integer division.

#### Examples

x = 7 % 5; // x now contains 2 x = 9 % 5; // x now contains 4 x = 5 % 5; // x now contains 0 x = 4 % 5; // x now contains 4

The modulo operator is useful for generating repeating patterns or series of numbers, such as getting a memory array to roll over

#### Example Program

// setup a buffer that averages the last five samples of a sensor

int senVal[5]; //create an array for sensor data

#### Common Programming Errors

the modulo operator will not work on floats