Page 61 - Programming the Photon Getting Started With the Internet of Things
P. 61

Data Type                 Memory (bytes)                            Range


          boolean                                    1              true or false (0 or 1)


          char                                       1              −128 to +128


          byte                                       1              0 to 255


          int                                        2              −32768 to +32767



          unsigned int                               2              0 to 65536


          long                                       4              2,147,483,648 to 2,147,483,647


          unsigned long                              4              0 to 4,294,967,295


          float                                      4              −34028235E+38 to +3.4028235E+38


          double                                     4              same as float



        Table 3.1 Variable Data Types

             Another thing to remember is what happens when your values exceed the limits. This

        causes odd things to happen. For example, if you have the byte variable with a value of
        255 and you suddenly add a 1 to this value, it returns a zero; similar to this, if you add a 1
        to an integer with the maximum value of 32767, it becomes a negative value of −32768.
        Usually, you can get away with most of your data types being an integer, so sometimes it’s

        best to use this data type by default.





        Char


        The  data  type  char  is  a  byte  that  represents  an  ASCII  character.  ASCII  (American

        Standard  Code  for  Information  Interchange)  is  a  system  from  the  very  early  days  of
        computing used to translate between bytes and characters. A char typically only takes up
        1  byte  of  memory  that  stores  a  character  value.  Single  characters  are  written  in  single

        quotes ‘A’ and multiple characters are written in double quotations “ABC.” In theory, a
        char is stored as a number according to the ASCII table (e.g., A is equal to the number 65).
        Here is how you create and assign a char variable:


                   char letter = ‘A’;
                   char letter = 65;


        Both examples of using char are correct.
   56   57   58   59   60   61   62   63   64   65   66