User Tools

Site Tools


arduino:data_types:unsignedint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

arduino:data_types:unsignedint [2013/02/15 20:45] (current)
Line 1: Line 1:
 +======unsigned int   ======
 +
 +====Description   ====
 +
 +On the Uno and other ATMEGA based boards, unsigned ints (unsigned integers) are the same as ints in that they store a 2 byte value. Instead of storing negative numbers however they only store positive values, yielding a useful range of 0 to 65,535 (2^16) - 1).
 +
 +The Due stores a 4 byte (32-bit) value, ranging from 0 to 4,294,967,295 (2^32 - 1).
 +
 +The difference between unsigned ints and (signed) ints, lies in the way the highest bit, sometimes refered to as the "sign" bit, is interpreted. In the Arduino  int type (which is signed), if the high bit is a "1", the number is interpreted as a negative number, and the other 15 bits are interpreted with [[http://en.wikipedia.org/wiki/2%27s_complement | 2's complement math.]] 
 +
 +====Example   ====
 +
 +    [=unsigned int ledPin = 13;=]
 +
 +====Syntax   ====
 +
 +    [= unsigned int var = val;=]
 +
 +*var - your unsigned int variable name
 +*val - the value you assign to that variable
 +
 +
 +====Coding Tip   ====
 +
 +When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacitiy, note that this happens in both directions
 +
 +<code arduino>   unsigned int x
 +   x = 0;
 +   x = x - 1;       // x now contains 65535 - rolls over in neg direction
 +   x = x + 1;       // x now contains 0 - rolls over
 +</code>
 +
 +====See Also   ====
 +
 +* [[arduino:data_types:Byte]]
 +* [[arduino:data_types:Int]]
 +* [[arduino:data_types:Long]]
 +* [[arduino:data_types:unsignedlong|unsignedlong]]
 +* [[arduino:variable scope and qualifiers:VariableDeclaration|Variable Declaration]]
 +Source: arduino.cc
  
advertising
arduino/data_types/unsignedint.txt · Last modified: 2013/02/15 20:45 (external edit)

Impressum Datenschutz