Are there any methods in objective C for converting byte to int, float and NSString?
+3
A:
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.
Max Seelemann
2010-08-30 12:13:04
What if I have an array of four byte and I want to convert it into int.
Ideveloper
2010-08-30 13:39:13
bitshift and add them. Like so: `int x = (arr[0] << 12) + (arr[1] << 8) + (arr[2] << 4) + arr[3]`
Max Seelemann
2010-08-30 13:44:37
That helped. Thanx alot
Ideveloper
2010-08-30 13:52:14