我从Contiki使用的无符号整数存储的测试中得到了几个数字,用C实现(即无符号整数),基本上不断添加到正数。
他们现在是负面的,所以我假设他们四处都是。有人让我得到整数的“实际”假设值。
所有整数都低于32768,所以我假设它在2 ^ 15处包裹。很多整数接近-32768,所以我假设它从32768变为-32768。
所以基本上,如果我得到一个像-23000这样的整数,它的实际假设值(在我的情况下)是(32768 +(32768 - 23000))= 42536?
这是对的吗?
编辑:
非常清楚,我在谈论contiki中定义的uipstats_t类型。 像这样:
struct uip_stats {
struct {
uip_stats_t recv; /**< Number of received packets at the IP
layer. */
uip_stats_t sent; /**< Number of sent packets at the IP
layer. */
uip_stats_t forwarded;/**< Number of forwarded packets at the IP
layer. */
uip_stats_t drop; /**< Number of dropped packets at the IP
layer. */
uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
IP version or header length. */
uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
IP length, high byte. */
uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
IP length, low byte. */
uip_stats_t fragerr; /**< Number of packets dropped because they
were IP fragments. */
uip_stats_t chkerr; /**< Number of packets dropped due to IP
checksum errors. */
uip_stats_t protoerr; /**< Number of packets dropped because they
were neither ICMP, UDP nor TCP. */
} ip;
它们是我的平台定义为:
typedef unsigned int uip_stats_t;
他们已经记录并呈现给我如下:
PRINTA("UIP STATS. recv %d sent %d drp %d\n",
uip_stat.ip.recv,
uip_stat.ip.sent,
uip_stat.ip.drop);
上面的代码印刷了数字。