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
加载中,请稍侯......
精彩评论