Abl-electronic PIC Microcontrollers PIC16 Manuel d'utilisateur Page 111

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 312
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 110
Binary Arithmetic Operators
Division of two integers returns an integer, while remainder is simply truncated:
/* for example: */
7 / 4;
// equals 1
7 * 3 / 4;
// equals 5
/* but: */
7. * 3./ 4.;
// equals 5.25 as we are working with floats
Remainder operand % works only with integers; sign of result is equal to the sign
of first operand:
/* for example: */
9 % 3;
// equals 0
7 % 3;
// equals 1
-7 % 3;
// equals -1
We can use arithmetic operators for manipulating characters:
'A' + 32;
// equals 'a' (ASCII only)
'G' - 'A' + 'a';
// equals 'g' (both ASCII and EBCDIC)
Unary Arithmetic Operators
Unary operators ++ and -- are the only operators in C which can be either prefix
(e.g.
++k, --k) or postfix (e.g. k++, k--).
When used as prefix, operators ++ and -- (preincrement and predecrement) add or
subtract one from the value of operand before the evaluation. When used as suffix,
operators
++ and -- add or subtract one from the value of operand after the evalu-
ation.
For example:
int j = 5; j = ++k;
/* k = k + 1, j = k, which gives us j = 6, k = 6 */
int j = 5; j = k++;
/* j = k, k = k + 1, which gives us j = 5, k = 6 */
MikroElektronika:
Development
tools
-
Books
-
Compilers
103
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
Vue de la page 110
1 2 ... 106 107 108 109 110 111 112 113 114 115 116 ... 311 312

Commentaires sur ces manuels

Pas de commentaire