Char

来自YFRobotwiki
2016年12月26日 (一) 21:06Allblue讨论 | 贡献的版本

跳转至: 导航搜索

char()

描述

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").

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.

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.

译:

一个数据类型,占用1个字节的内存存储一个字符值。字符都写在单引号,如'A'(多个字符(字符串)使用双引号,如“ABC”)。

字符以编号的形式存储。你可以在ASCII表中看到对应的编码。这意味着字符的ASCII值可以用来作数学计算。(例如'A'+ 1,因为大写A的ASCII值是65,所以结果为66)。如何将字符转换成数字参考serial.println命令。

char数据类型是有符号的类型,这意味着它的编码为-128到127。对于一个无符号一个字节(8位)的数据类型,使用byte数据类型。


示例

A function to compare a sensor input to a threshold

  char myChar = 'A';
  char myChar = 65;      // both are equivalent


扩展阅读

- byte
- int
- array
- Serial.println




返回Arduino语法参考列表

更多建议和问题欢迎反馈至 YFRobot论坛