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.