Char

從 YFRobotwiki
跳到: 導覽搜尋

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數據類型。


示例

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


擴展閱讀

- byte
- int
- array
- Serial.println




返回Arduino語法參考列表

更多建議和問題歡迎反饋至 YFRobot論壇