开发者

Byte to int, float, NSString conversion

开发者 https://www.devze.com 2023-01-13 21:56 出处:网络
Are there any methods in objective C for converting byte to in开发者_开发技巧t, float and NSString?The first are C-types. No conversion is needed, just assign them:

Are there any methods in objective C for converting byte to in开发者_开发技巧t, float and NSString?


The first are C-types. No conversion is needed, just assign them:

byte b = ...;

int x = b;
float f = b;

Converting to NSString could be done using stringWithFormat:, a NSNumberFormatter and many more methods. This is the easiest:

NSString *myString = [NSString stringWithFormat: @"%d", b];

If you want it printed in hex, use @"%x" (for lowercase letters) or @"%X" (for capital letters) instead.


You could get an NSString from NSData with initWithData:encoding: and then transform it into int or float by calling intValue and floatValue

0

精彩评论

暂无评论...
验证码 换一张
取 消