how to convert byte value into int in objective-c

后端 未结 5 1249
感动是毒
感动是毒 2021-01-01 06:24

Please tell me how to convert bytes to NSInteger/int in objective-c in iPhone programming?

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 07:00

    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;
    

    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

    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.

提交回复
热议问题