Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 306285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:27:10+00:00 2026-05-12T07:27:10+00:00

I have an unsigned long long value which I want to store into an

  • 0

I have an unsigned long long value which I want to store into an NSString and retrieve from the string.

Initially I have the value in an NSNumber and I am using this to get the string

NSString *numStr = [NSString stringWithFormat:@"%llu", [myNum unsignedLongLongValue]];

where myNum is an NSNumber.

To get back the NSNumber from the NSString I have to first get the unsigned long long value. But there is no method in the NSString class to do that (we just have one for getting the long long value, not the unsigned long long value).

Can someone please tell me how I can get back the value into an NSNumber variable.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:27:10+00:00Added an answer on May 12, 2026 at 7:27 am

    There are a lot of ways to accomplish this. The following is the most pragmatic:

    NSString *numStr = [NSString stringWithFormat:@"%llu", [myNum unsignedLongLongValue]];
    
    // .. code and time in between when numStr was created
    // .. and now needs to be converted back to a long long.
    // .. Therefore, numStr used below does not imply the same numStr above.
    
    unsigned long long ullvalue = strtoull([numStr UTF8String], NULL, 0);
    

    This makes a few reasonable assumptions such as numStr will only contain numeric digits and it contains a ‘valid’ unsigned long long value. A drawback to this approach is that UTF8String creates what essentially amounts to [[numStr dataUsingEncoding:NSUTF8StringEncoding] bytes], or in other words something along the lines of 32 bytes of autoreleased memory per call. For the vast majority of uses, this is no problem what-so-ever.

    For an example of how to add something like unsignedLongLongValue to NSString that is both very fast and uses no autoreleased memory as a side effect, take a look at the end of my (long) answer to this SO question. Specifically the example implementation of rklIntValue, which would require only trivial modifications to implement unsignedLongLongValue.

    More information regarding strtoull can be found in its man page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a unsigned long integer value which represents a float using IEEE-754 format.
What's the safest and best way to retrieve an unsigned long from a string
I have unsigned char* , want to convert it to std::string . Can you
In my embedded c program I have a struct: struct var{ unsigned long value;
I have 3 base representations for positive integer numbers: Decimal, in unsigned long variable
I have a incoming stream of bytes (unsigned char) from either a file or
I have values that are 64-bit unsigned ints, and I need to store them
I have a question regarding using intptr_t vs. long int . I've observed that
Hi I want to send a value from my matlab to my mex function.
I have the following struct in C++: struct routing_entry { unsigned long destSeq; //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.