unsigned int
描述
在 86Duino 上無號整數和有號整數一樣,都儲存在 4 byte (32 bits) 的空間,因為不能儲存負數,因此儲存正整數的範圍擴大為 0 到 4,294,967,295 (2^32 – 1)。
有號數與無號數之間的差別在於最高位元,在有號數的時候他會被解釋成正負號的位元,86Duino 中,有號數的最高位元是 1 時,該數值為負數,其他位元將會用 2的補數 表示。
範例
unsigned int ledPin = 13;
語法
unsigned int var = val;
var
– 無號數的變數名稱
val
– 指派數值給變數
提醒
當變數超過他們的最大值時,會回捲到最小值再加上去,相反的亦是如此。
unsigned int x x = 0; x = x - 1; // x 現在是 4,294,967,295 - 回捲到 unsigned int 的最大值 x = x + 1; // x 現在是 0 - 回捲到 unsigned int 的最小值
See also
- byte
- int
- long
- unsigned long
- Variable Declaration
本頁由熱血青年 LBU 譯自英文版。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.