开发者

Byte to int, float, NSString conversion

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜