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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:43:09+00:00 2026-05-24T04:43:09+00:00

How to gracefully use snprintf function or some another function from standard C library

  • 0

How to gracefully use snprintf function or some another function from standard C library to fill the memory by ASCII representation of an array of unsigned char?

char data[16];
char dataRepresentation[33];
...
for (i = 0; i < 16; ++i)
        snprintf(&dataRepresentation[i * 2], 3, "%02x", (unsigned char) data[i])

Is it the easiest way to get the ASCII representation?

  • 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-24T04:43:11+00:00Added an answer on May 24, 2026 at 4:43 am

    A bit of bit-twiddling will go much faster:

    char data[16];
    char dataRepresentation[2 * sizeof data];
    static const char master[] = "01234567890abcdef";
    ...
    for (i = 0; i < sizeof data; ++i)
    {
         dataRepresentation[i * 2] = master[0xF&(data[i]>>4)];
         dataRepresentation[i * 2 + 1] = master[data[i]&0xF];
    }
    

    Beware that I haven’t actually compiled this code.

    • 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 trap an error and exit gracefully from Perl? I
I'm having some problems getting my object to gracefully fail out if an invalid
After the you guys helped me out so gracefully last time, here is another
Why does this print garbage instead of exiting my program gracefully? I use system
In order for my webpage to degrade gracefully, I have some CSS that should
How do you gracefully handle failed future feature imports? If a user is running
How do I stop a Java process gracefully in Linux and Windows? When does
I'm taking the leap: my PHP scripts will ALL fail gracefully! At least, that's
Is there a PostgreSQL HA solution that can handle a splitbrain situation gracefully. To
** EDIT November 17th ** Hi again, I wanted to show some code you

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.