aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/lang/cpp/unsignedint.rst
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2014-08-27 17:36:11 -0400
committerbnewbold <bnewbold@robocracy.org>2014-08-27 17:42:22 -0400
commit34b766c9d5f778762069938c71e052fa40455d1c (patch)
tree3a2b77e636b222fecff6366218cf7845029afecf /docs/source/lang/cpp/unsignedint.rst
parent746d6fecf86572c9fe95dbbffdf541a8d3875dd0 (diff)
parentadd7e54ccaf61859874527feda2b51ea172ce697 (diff)
downloadlibrambutan-34b766c9d5f778762069938c71e052fa40455d1c.tar.gz
librambutan-34b766c9d5f778762069938c71e052fa40455d1c.zip
merge libmaple docs ("leaflabs-docs") into ./docs
In the past, libample documentation was forked out of this repository because the documentation had increased in scope. For the librambutan, and the rambutan project in general, we will try to keep documentation closer to the source code, so the librambutan-specific documentation should live here. Other sections of leaflabs-docs will be culled in a following commit. This merge attempts to maintain history by using a subtree strategy. Followed directions at: http://nuclearsquid.com/writings/subtree-merging-and-you/ Full history for files should be accessible using the "--follow" flag to git log, eg: git log --follow docs/source/adc.rst It should be possible to pull patches from leaflabs-docs with: git pull -s subtree leaflabs-docs master ... at least until the docs in this repository diverge significantly.
Diffstat (limited to 'docs/source/lang/cpp/unsignedint.rst')
-rw-r--r--docs/source/lang/cpp/unsignedint.rst59
1 files changed, 59 insertions, 0 deletions
diff --git a/docs/source/lang/cpp/unsignedint.rst b/docs/source/lang/cpp/unsignedint.rst
new file mode 100644
index 0000000..f8ea473
--- /dev/null
+++ b/docs/source/lang/cpp/unsignedint.rst
@@ -0,0 +1,59 @@
+.. highlight:: cpp
+
+.. _lang-unsignedint:
+
+``unsigned int``
+================
+
+An ``unsigned int`` (unsigned integer) is the same as an :ref:`int
+<lang-int>` in that it stores a 4 byte integer value. However,
+Instead of storing both negative and positive numbers, an ``unsigned
+int`` can only store nonnegative values, yielding a range of 0 to
+4,294,967,295 (the positive value is 2^32 - 1).
+
+The difference between an ``unsigned int`` and a (signed) ``int`` lies
+in the way the highest bit, sometimes referred to as the "sign" bit,
+is interpreted. In the case of the Maple ``int`` type (which is
+signed), if the high bit is a "1", the number is interpreted as a
+negative number, using a technique known as `two's complement math
+<http://en.wikipedia.org/wiki/Two%27s_complement#Explanation>`_. The
+bits in an an ``unsigned int`` are interpreted according to the usual
+rules for converting `binary to decimal
+<http://en.wikipedia.org/wiki/Binary_numeral_system#Counting_in_binary>`_.
+
+An ``unsigned int`` is subject to the same :ref:`overflow issues
+<lang-int-overflow>` as a regular ``int``; the only difference is
+that an ``unsigned int`` will "underflow" at 0, and "overflow" at
+4,294,967,295. Here is some example code which illustrates this::
+
+ unsigned int x;
+ x = 0;
+ x--; // x now contains 4,294,967,295; rolled over "left to right"
+ x++; // x now contains 0; rolled over "right to left"
+
+.. _lang-unsignedlong:
+
+The ``unsigned long`` type is a synonym for ``unsigned int``.
+
+Here is an example of declaring an ``unsigned int`` variable named
+``pin``, then giving it value 13::
+
+ unsigned int pin = 13;
+
+The general syntax for declaring an ``unsigned int`` variable named
+``var``, then giving it value ``val``, looks like::
+
+ unsigned int var = val;
+
+See Also
+--------
+
+- :ref:`int <lang-int>`
+- :ref:`char <lang-char>`
+- :ref:`unsigned char <lang-unsignedchar>`
+- :ref:`long long <lang-longlong>`
+- :ref:`unsigned long long <lang-unsignedlonglong>`
+- :ref:`Integer Constants <lang-constants-integers>`
+- :ref:`Variables <lang-variables>`
+
+.. include:: /arduino-cc-attribution.txt