How can I convert hex number to integers and strings in Objective C?

To get the decimal and hexadecimal equivalents, you would do.

Up vote 2 down vote favorite share g+ share fb share tw.

Given the example of an array like this: idx = 0xe, 0x3, 0x6, 0x8, 0x2 I want to get an integer and string representation of each of the specified items in Objective C. I have mocked up a ruby example which works perfectly: 0xe gives 14 when I run 0xe. To_i and "e" when I run to_i(base=16) 0x3 gives 3 when I run 0x3.

To_i and gives 3 when I run to_i(base=16) How can I achieve this in Objective C? Objective-c cocoa hex link|improve this question edited Jun 1 '09 at 13:27GEOCHET11.1k93258 asked Jun 1 '09 at 13:20Grzegorz Kazulak5016 50% accept rate.

– sbooth Jun 1 '09 at 14:07 Yes. They are not-localized. – Grzegorz Kazulak Jun 2 '09 at 5:51.

To get the decimal and hexadecimal equivalents, you would do: int number = 0xe; // or 0x3, 0x6, 0x8, 0x2 NSString * decimalString = NSString stringWithFormat:@"%d", number; NSString * hexString = NSString stringWithFormat:@"%x", number.

Thanks, Ok that's a bit helpfull. But can I store 0xe in NSNumber? I cannot assign it to a int as I want to store this stuff in NSArray as you can't use standard C types in it (mutable or not) – Grzegorz Kazulak Jun 1 '09 at 16:44 1 NSNumber can wrap any of the primitive numeric types.

Of course, once you're making string representations of the numbers, you could store the strings in the array. – Peter Hosey Jun 1 '09 at 17:14.

Once you have an NSString you can just use the methods in that class, like intValue or longValue or floatValue.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions