marty
marty

Reputation: 391

What's the largest variable value in iphone?

I need to assign 2,554,416,000 to a variable. What would be the primitive to use, and what would be the object representation class to use? Thanks.

Upvotes: 2

Views: 156

Answers (4)

Michael Dorgan
Michael Dorgan

Reputation: 12515

You could store it in a regular int scaled down by 1000 if you wanted, if this represented a score that could never have the bottom 3 digits hold any info or something similiar. This would be a way to save a few bits and possibly an entire extra int of space, if that matters.

Upvotes: 0

Alex Wayne
Alex Wayne

Reputation: 186984

Chuck is right, but in answer to the "object representation", you want NSNumber used with the unsignedInt methods.

NSNumber *myNum = [NSNumber numberWithUnsignedInt:2554416000];
NSUInteger myInt = [myNum unsignedIntValue];

Upvotes: 1

Chuck
Chuck

Reputation: 237010

This can be represented by a 32-bit unsigned integer (UINT_MAX is about 4 billion). That's actually what NSUInteger is on the iPhone, but if you want to be very specific about the bit width, you could specify a uint32_t.

Upvotes: 1

kennytm
kennytm

Reputation: 523154

2,554,416,000 = 0x9841,4B80 ≤ 0xFFFF,FFFF (UINT_MAX), so uint32_t (unsigned int) or int64_t (long long).

A signed int32_t (int) cannot represent this because 0x9841,4B80 > 0x7FFF,FFFF (INT_MAX). Storing it in an int will make it negative.

Upvotes: 1

Related Questions