Int

From Microduino Wiki
Jump to: navigation, search
  • Introduction

The integer is the basic data type, occupying 2 bytes. The range of integers is from -32,768 to 32,767( -2^15 ~(2^15)-1).

Int stores negative numbers in complement code of 2. The peak bit is usually the sign bit, which represents the negative or positive of the number. And the other bits are “inverted and add 1”(please refer to the materials about complement code here, needless ).

Arduino can deal with the calculation of negatives, so math is transparent to you(term:actual existence, which can not be operated, equivalent to“black box”).However, when dealing with the right shift operator(»), there may be unexpected compilation process.

  • Example
int ledPin = 13;
  • Syntax
int var = val;
  • var - name of the variable
  • val - the value to resign to variable
  • Promotion

When the variable too large, and exceeds the range of integer type can represent(-32,768 to 32,767), the value of the variable will “roll-back”(see the sample).

   int x
   x = -32,768;
   x = x - 1;       // x is 32,767 now.
 
   x = 32,767;
   x = x + 1;       // x is -32,768 now.

[Return to Arduino Syntax Manual]