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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:33:29+00:00 2026-05-16T06:33:29+00:00

Is there any standard C function that converts from hexadecimal string to byte array

  • 0

Is there any standard C function that converts from hexadecimal string to byte array?
I do not want to write my own function.

  • 1 1 Answer
  • 1 View
  • 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-16T06:33:30+00:00Added an answer on May 16, 2026 at 6:33 am

    As far as I know, there’s no standard function to do so, but it’s simple to achieve in the following manner:

    #include <stdio.h>
    
    int main(int argc, char **argv) {
        const char hexstring[] = "DEadbeef10203040b00b1e50", *pos = hexstring;
        unsigned char val[12];
    
         /* WARNING: no sanitization or error-checking whatsoever */
        for (size_t count = 0; count < sizeof val/sizeof *val; count++) {
            sscanf(pos, "%2hhx", &val[count]);
            pos += 2;
        }
    
        printf("0x");
        for(size_t count = 0; count < sizeof val/sizeof *val; count++)
            printf("%02x", val[count]);
        printf("\n");
    
        return 0;
    }
    

    Edit

    As Al pointed out, in case of an odd number of hex digits in the string, you have to make sure you prefix it with a starting 0. For example, the string "f00f5" will be evaluated as {0xf0, 0x0f, 0x05} erroneously by the above example, instead of the proper {0x0f, 0x00, 0xf5}.

    Amended the example a little bit to address the comment from @MassimoCallegari

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

Sidebar

Related Questions

Is there any way to create a function/callable object that inherits properties from another
Are there any php function that do this: $source = array('id1'=>'name', 'id2'=>'name2', 'id3'=>'name3'); $keys
Is there any standard way of debugging Javascript on a webpage that's being accessed
Is there any standard way to route all Key events from the control A
Is there any standard way of implementing some sort of a write-through buffer for
Is there any standard/documented ways to implement two-finger tap event in WP7? If not,
Is there any safe and standard compliant way to treat a C style array
Is there any way to start foobar.js WSH-script in order that standard Task Manager
Is there any easy way to change the color of the UITableViewCellAccessoryCheckmark from standard
Is there any function that allow me to compute the CDF probability of a

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.