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

  • SEARCH
  • Home
  • 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 6590919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:21:36+00:00 2026-05-25T17:21:36+00:00

When I call -description on an NSData object, I see a pretty Hex string

  • 0

When I call -description on an NSData object, I see a pretty Hex string of the NSData object’s bytes like:

<f6e7cd28 0fc5b5d4 88f8394b af216506 bc1bba86 4d5b483d>

I’d like to get this representation of the data (minus the lt/gt quotes) into an in-memory NSString so I can work with it.. I’d prefer not to call -[NSData description] and then just trim the lt/gt quotes (because I assume that is not a guaranteed aspect of NSData‘s public interface and is subject change in the future).

What’s the simplest way to get this representation of an NSData object into an NSString object (other than calling -description)?

  • 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-25T17:21:37+00:00Added an answer on May 25, 2026 at 5:21 pm

    Keep in mind that any String(format: ...) solution will be terribly slow (for large data)

    NSData *data = ...;
    NSUInteger capacity = data.length * 2;
    NSMutableString *sbuf = [NSMutableString stringWithCapacity:capacity];
    const unsigned char *buf = data.bytes;
    NSInteger i;
    for (i=0; i<data.length; ++i) {
      [sbuf appendFormat:@"%02X", (NSUInteger)buf[i]];
    }
    

    If you need something more performant try this:

    static inline char itoh(int i) {
        if (i > 9) return 'A' + (i - 10);
        return '0' + i;
    }
    
    NSString * NSDataToHex(NSData *data) {
        NSUInteger i, len;
        unsigned char *buf, *bytes;
        
        len = data.length;
        bytes = (unsigned char*)data.bytes;
        buf = malloc(len*2);
        
        for (i=0; i<len; i++) {
            buf[i*2] = itoh((bytes[i] >> 4) & 0xF);
            buf[i*2+1] = itoh(bytes[i] & 0xF);
        }
        
        return [[NSString alloc] initWithBytesNoCopy:buf
                                              length:len*2
                                            encoding:NSASCIIStringEncoding
                                        freeWhenDone:YES];
    }
    

    Swift version

    
    private extension Data {
        var hexadecimalString: String {
            let charA: UInt8 = 0x61
            let char0: UInt8 = 0x30
            func byteToChar(_ b: UInt8) -> Character {
                Character(UnicodeScalar(b > 9 ? charA + b - 10 : char0 + b))
            }
            let hexChars = flatMap {[
                byteToChar(($0 >> 4) & 0xF),
                byteToChar($0 & 0xF)
            ]}
            return String(hexChars)
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a good primer or technical description of the System Call
when i call uploadifySettings(scriptData, { 'description': description }); it mean that param description is
ok this is an Api call $json_string = 'offices: [{description: Google Headquarters, address1: 1600
In this code: soup=BeautifulSoup(program.Description.encode('utf-8')) name=soup.find('div',{'class':'head'}) print name.string.decode('utf-8') error happening when i'm trying to print
As the description of title, Which interface of UIWebView should I call to get
I'm trying to call a function which writes a very long string of html
We have 4 normalized tables, for description sake we will call them t1, t2,t3,t4.
Problem Description I have a string S. How can I find if the string
Function call from javascript Test.show({title : Text,body : Description }); How can I call
Decimal: 143196173 Hex: 0x889000D Results from a call to IAudioSessionControl2->GetProcessId() . GetLastError = 126*

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.