Ideveloper
Ideveloper

Reputation: 1463

Byte to int, float, NSString conversion

Are there any methods in objective C for converting byte to int, float and NSString?

Upvotes: 0

Views: 2315

Answers (2)

rano
rano

Reputation: 5666

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

Upvotes: 0

Max Seelemann
Max Seelemann

Reputation: 9364

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.

Upvotes: 3

Related Questions