如何字节值转换成int类型的Objective-C [英] how to convert byte value into int in objective-c
问题描述
请告诉我如何字节转换为NSInteger的/ INT在Objective-C在iPhone编程?
Please tell me how to convert bytes to NSInteger/int in objective-c in iPhone programming?
推荐答案
您的问题没有用Objective-C的关系,它只是纯C,它应该被标为C。
Your question is not related with Objective-C, it is just pure c, and it should be tagged "c".
你说的字节是什么意思?
如果你想转换一个字节再presenting整数值INT(或NSInteger的)类型,只要使用=
What do you mean by "Bytes"? If you want convert single byte representing integer value to int (or NSInteger) type, just use "=":
Byte b = 123;
NSInteger x;
x = b;
为字节(同为 unsigned char型 - 1字节的无符号整数)和NSInteger的(同为 INT - 4字节有符号整数)都是简单的整数类型并可以自动转换。你应该阅读更多关于 C数据类型的和转换规则的。
例如的http://www.exforsys.com/tutorials/c-language/c-programming-language-data-types.html
as Byte (the same as unsigned char - 1 byte unsigned integer) and NSInteger (the same as int - 4 bytes signed integer) are both of simple integer types and can be converted automatically. Your should read more about "c data types" and "conversion rules". for example http://www.exforsys.com/tutorials/c-language/c-programming-language-data-types.html
如果要转换多个字节存储一些值为int,然后皈依取决于这些数据结构:每个值多少字节,怎么带符号。
If you want to convert several bytes storing some value to int, then convertion depends on structure of these data: how many bytes per value, signed or unsigned.
这篇关于如何字节值转换成int类型的Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!