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 8850187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:50:33+00:00 2026-06-14T12:50:33+00:00

Very basic Question. :(. I have a hex value and trying to accommodate into

  • 0

Very basic Question. :(. I have a hex value and trying to accommodate into NSData, and
tried the following.

  unsigned char  bytes [] = {0x0f0121dd06a2d00503040705aa010ba2d0a2d0};
  NSData *data = [NSData dataWithBytes: bytes  length:19];
  NSLog (@" DAta is %@ ", data);

I m getting the following Warning

34:37: warning: integer constant is too large for its type
34: warning: large integer implicitly truncated to unsigned type

Data is printed like:

NSDataExample[36136:707]  DAta is <d028e08c 7fff7f00 00000000 00000000 0008fc>

I m not sure if i m doing it in a right way?. Kindly advice.

  • 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-06-14T12:50:35+00:00Added an answer on June 14, 2026 at 12:50 pm

    You aren’t assigning the char array properly it seems; because it is too large for the type you’re assigning. How about this, as an example:

    #import <Foundation/Foundation.h>
    
    int main(int argc, char *argv[]) {
        NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
    
        // your example has longer hex value, truncated here for clarity...
        unsigned char bytes[] = { 0x0F, 0x01, 0x21};
        NSData *data = [NSData dataWithBytes:bytes  length:3];
        NSLog (@" Data is %@ ", data);
    
        [p release];
    }
    

    Prints 2012-11-19 06:40:07.581 Untitled 2[12472:707] Data is <0f0121> to the console

    Or, if your hex bytes are in the form of a string, something like this:

    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[])
    {
    
        @autoreleasepool {
            NSString *hexString = @"0x0f0121dd06a2d00503040705aa010ba2d0a2d0";
            NSMutableData *data = [[NSMutableData alloc] init];
            NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"[A-Fa-f0-9]{2}" options:0 error:NULL];
            [expression enumerateMatchesInString:hexString options:0 range:NSMakeRange(0, hexString.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
                int hex = (int)strtol([[hexString substringWithRange:result.range] UTF8String], NULL, 16);
                printf("hex = %d\n",hex);
                [data appendBytes:&hex length:1];
            }];
            NSLog(@"%s - data = %@",__FUNCTION__,data);
        }
        return 0;
    }
    

    Which prints 2012-11-19 06:56:15.753 TestHexStringToBytes[12891:303] main - data = <0f0121dd 06a2d005 03040705 aa010ba2 d0a2d0> to the console.

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

Sidebar

Related Questions

Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
I have a seemingly very basic question. I'm trying to decide whether or not
I have a very basic question and need help. I am trying to understand
Very basic question - but I couldn't find an answer. I have got a
A very basic question in excel. I have a column with valid and with
I have a very basic question. Lets take this snippet: #include <stdio.h> void foo(void)
I have a very basic question. Scenario: 2 forms Form1, Form2- Dialog box which
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I'm a Ruby newbie. Have a very basic question about static and instance variables.
quick and very basic newbie question. If i have list of dictionaries looking like

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.