sus*_*use 3 c iphone byte integer objective-c
请告诉我如何在iPhone编程的objective-c中将字节转换为NSInteger/int?
如果按字节,你的意思是一个无符号的 8 位值,下面会做。
uint8_t foo = 3; // or unsigned char foo...
NSInteger bar = (NSInteger) foo;
Run Code Online (Sandbox Code Playgroud)
甚至
NSInteger bar = foo;
Run Code Online (Sandbox Code Playgroud)
你对"字节"是什么意思?如果要将表示整数值的单字节转换为int(或NSInteger)类型,只需使用"=":
Byte b = 123;
NSInteger x;
x = b;
Run Code Online (Sandbox Code Playgroud)
as Byte(与unsigned char - 1字节无符号整数相同)和NSInteger(与int - 4字节有符号整数相同)都是简单整数类型,可以自动转换.您应该阅读有关" c数据类型 "和" 转换规则 "的更多信息.例如http://www.exforsys.com/tutorials/c-language/c-programming-language-data-types.html
如果要将存储某些值的多个字节转换为int,则convertion取决于这些数据的结构:每个值有多少字节,有符号或无符号.
| 归档时间: |
|
| 查看次数: |
19226 次 |
| 最近记录: |