From 85c1c72db022bba891868afd3375e39dbe245701 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 20 Oct 2010 06:46:52 -0400 Subject: initial check-in of arduino docs in RST format (converted using wget+pandoc) --- source/arduino/unsignedint.rst | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 source/arduino/unsignedint.rst (limited to 'source/arduino/unsignedint.rst') diff --git a/source/arduino/unsignedint.rst b/source/arduino/unsignedint.rst new file mode 100644 index 0000000..10835fe --- /dev/null +++ b/source/arduino/unsignedint.rst @@ -0,0 +1,77 @@ +.. _arduino-unsignedint: + +unsigned int +============ + +Description +----------- + +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 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 +`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 + + + +:: + + 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 + + + +See Also +-------- + + +- `byte `_ +- `int `_ +- `long `_ +- `unsigned long `_ +- `Variable Declaration `_ + + -- cgit v1.2.3