From 2d429e75ce69e77f8c95490ac03881ec9aa0354a Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 25 Oct 2010 21:15:28 -0400 Subject: arduino language reference nearing completion, properly CC-BY-SA 3.0 attributed --- source/arduino/char.rst | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'source/arduino/char.rst') diff --git a/source/arduino/char.rst b/source/arduino/char.rst index e783ed6..53dd060 100644 --- a/source/arduino/char.rst +++ b/source/arduino/char.rst @@ -1,3 +1,5 @@ +.. highlight:: cpp + .. _arduino-char: char @@ -6,28 +8,25 @@ char Description ----------- -A data type that takes up 1 byte of memory that stores a character -value. Character literals are written in single quotes, like this: -'A' (for multiple characters - strings - use double quotes: -"ABC"). - - +The ``char`` type stores a 1-byte character value (or integer with +value from -128 to 127). Character literals are written in single +quotes, like this: ``'A'`` (for multiple characters - strings - use +double quotes: ``"ABC"``). -Characters are stored as numbers however. You can see the specific -encoding in the -`ASCII chart `_. This -means that it is possible to do arithmetic on characters, in which -the ASCII value of the character is used (e.g. 'A' + 1 has the -value 66, since the ASCII value of the capital letter A is 65). See -`Serial.println `_ reference -for more on how characters are translated to numbers. +Just like everything else on a computer, characters are stored as +numbers. You can see the specific encoding in the `ASCII chart +`_\ +. This means that it is possible to do arithmetic on characters, in +which the ASCII value of the character is used (e.g. ``'A' + 1`` has the +decimal value 66, since the ASCII value of the capital letter A in +decimal is 65). See the :ref:`Serial.println() +` documentation for more information about how +characters are converted into numbers. - -The char datatype is a signed type, meaning that it encodes numbers -from -128 to 127. For an unsigned, one-byte (8 bit) data type, use -the *byte* data type. - +The ``char`` datatype is a signed type, meaning that it encodes +numbers from -128 to 127. For an unsigned type, which stores values +from 0 to 255, just use the type ``unsigned char`` (two words). Example @@ -35,17 +34,16 @@ Example :: - char myChar = 'A'; - char myChar = 65; // both are equivalent - + // the following two lines are equivalent: + char c = 'A'; + char c = 65; See also -------- -- `byte `_ -- `int `_ -- `array `_ -- `Serial.println `_ +- :ref:`arduino-int` +- :ref:`arduino-array` (a string is just an array of ``char``\ s) +- :ref:`Serial.println() ` -- cgit v1.2.3