Unsigned int

From Microduino Wiki
Revision as of 07:35, 18 August 2016 by Fengfeng (talk) (Created page with "unsigned int<br> *'''Description'''<br> The size of unsigned int is same to int, occupying 2 bytes. It can only be used to store positive, and the range is 0~65,535 (2^16) -...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

unsigned int

  • Description

The size of unsigned int is same to int, occupying 2 bytes. It can only be used to store positive, and the range is 0~65,535 (2^16) - 1).

The most important difference between unsigned int and int is their peaks are different, namely the sign bit. In Arduino int, if the peak is 1, he number is taken as negative. The rest 15 btis are the values of the calculation according to the 2’s complement.

  • Example
unsigned int ledPin = 13;
  • Syntax
unsigned int var = val;
  • var - the name of the unsigned variable
  • val - the value to be assigned to the variable


  • Note

When the value of the variable exceeds the maximum value it can represent, it will “roll back ”to the minimum value, and reverse will also appear this phenomenon.

   unsigned int x
       x = 0;
   x = x - 1;       //x is equal to 65535 now--roll back the negative direction
   x = x + 1;       //x is equal to 0 now--roll back

[Return to Arduino Syntax Manual]