c_各个unsigned int 和 int的取值范围

bool, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t 取值范围分别是什么?

定义形式:

typedef unsigned char uint8_t;

typedef unsigned short uint16_t;

typedef unsigned int uint32_t;

typedef unsigned long uint64_t;

typedef signed char int8_t;

typedef signed short int16_t;

typedef signed int int32_t;

typedef signed long int64_t;

布尔类型

  • bool:在 C 和 C++ 中,布尔类型 bool 只能取两个值:truefalse。一般来说,false 代表 0,true 代表非零值(通常是 1)。

无符号整数类型

  • uint8_t:无符号 8 位整数。

    • 取值范围:0 到 255
    • 计算:2^8 = 256,范围是 0 到 256 - 1。
  • uint16_t:无符号 16 位整数。

    • 取值范围:0 到 65,535
    • 计算:2^16 = 65,536,范围是 0 到 65,536 - 1。
  • uint32_t:无符号 32 位整数。

    • 取值范围:0 到 4,294,967,295
    • 计算:2^32 = 4,294,967,296,范围是 0 到 4,294,967,296 - 1。
  • uint64_t:无符号 64 位整数。

    • 取值范围:0 到 18,446,744,073,709,551,615
    • 计算:2^64 = 18,446,744,073,709,551,616,范围是 0 到 18,446,744,073,709,551,616 - 1。

有符号整数类型

  • int8_t:有符号 8 位整数。

    • 取值范围:-128 到 127
    • 计算:-2^7 到 2^7 - 1。
  • int16_t:有符号 16 位整数。

    • 取值范围:-32,768 到 32,767
    • 计算:-2^15 到 2^15 - 1。
  • int32_t:有符号 32 位整数。

    • 取值范围:-2,147,483,648 到 2,147,483,647
    • 计算:-2^31 到 2^31 - 1。
  • int64_t:有符号 64 位整数。

    • 取值范围:-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
    • 计算:-2^63 到 2^63 - 1。

总结

类型比特位数取值范围
bool1truefalse
uint8_t80 到 255
uint16_t160 到 65,535
uint32_t320 到 4,294,967,295
uint64_t640 到 18,446,744,073,709,551,615
int8_t8-128 到 127
int16_t16-32,768 到 32,767
int32_t32-2,147,483,648 到 2,147,483,647
int64_t64-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惊鸿一博

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值