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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:27:15+00:00 2026-05-27T10:27:15+00:00

I have a variable length string where each character represents a hex digit. I

  • 0

I have a variable length string where each character represents a hex digit. I could iterate through the characters and use a case statement to convert it to hex but I feel like there has to be a standard library function that will handle this. Is there any such thing?

Example of what I want to do. "17bf59c" -> int intarray[7] = { 1, 7, 0xb, 0xf, 5, 9, 0xc}

  • 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-27T10:27:16+00:00Added an answer on May 27, 2026 at 10:27 am

    No, there’s no such function, probably because (and now I’m guessing, I’m not a C standard library architect by a long stretch) it’s something that’s quite easy to put together from existing functions. Here’s one way of doing it decently:

    int * string_to_int_array(const char *string, size_t length)
    {
      int *out = malloc(length * sizeof *out);
      if(out != NULL)
      {
        size_t i;
        for(i = 0; i < length; i++)
        {
          const char here = tolower(string[i]);
          out[i] = (here <= '9') ? (here - '\0') : (10 + (here - 'a'));
        }
      }
      return out;
    }
    

    Note: the above is untested.

    Also note things that maybe aren’t obvious, but still subtly important (in my opinion):

    1. Use const for pointer arguments that are treated as “read only” by the function.
    2. Don’t repeat the type that out is pointing at, use sizeof *out.
    3. Don’t cast the return value of malloc() in C.
    4. Check that malloc() succeeded before using the memory.
    5. Don’t hard-code ASCII values, use character constants.
    6. The above still assumes an encoding where ‘a’..’f’ are contigous, and would likely break on e.g. EBCDIC. You get what you pay for, sometimes. 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string of a variable length and at the end of the
I have a java string, which has a variable length. I need to put
I have lists of variable length where each item can be one of four
I have a table that contains in one column a variable length delimited string
I have been working on some legacy C++ code that uses variable length structures
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I want to replace each character of a string by a different one, shifted
I have a string such as 'xxox-x' that I want to mask each line
I have a list of variable length and am trying to find a way
I have a variable string like such: [Text that changes]:SPACE: where the :SPACE: is

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.