Ara*_*and 25 objective-c uint32 ios
UInt32的最大值是多少?
有没有办法可以使用sizeof运算符来获取最大值(因为它是无符号的)?所以我的代码中最终没有#defines或魔术数字.
Cou*_*per 45
您可以使用UINT32_MAX定义的宏stdint.h
#include <stdint.h>
uint32_t max = UINT32_MAX;
Run Code Online (Sandbox Code Playgroud)
<stdint.h>:http://pubs.opengroup.org/onlinepubs/009695299/basedefs/stdint.h.html
只需使用标准十六进制表示法设置最大值,然后根据需要进行检查即可。32位是8个十六进制字节,因此如下所示:
let myMax: UInt32 = 0xFFFFFFFF
if myOtherNumber > myMax {
// resolve problem
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62624 次 |
| 最近记录: |