DatatypeConversion \ Learning \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

This example is for Wiring version 0023+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Datatype Conversion.
It is sometimes beneficial to convert a value from one type of data to another. Each of the conversion functions converts its parameter to an equivalent representation within its datatype. The conversion functions include int(), float(), char(), byte(), and others.

    char c;    // Chars are used for storing typographic symbols
    float f;   // Floats are decimal numbers
    int i;     // Ints are values between -32,768 and 32.767
    byte b;    // Bytes are values between 0 and 255

    void setup() {
      c = 'A';
      f = float(c);     // Sets f = 65.0
      i = int(f * 1.4); // Sets i to 91
      b = (c / 2);  // Sets b to 32
      Serial.begin(9600);
      Serial.println(c);
      Serial.println(f);
      Serial.println(i);
      Serial.println(b, DEC);
    }

    void loop() {

    }