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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:12:49+00:00 2026-05-23T03:12:49+00:00

I have: uint8 buf[] = {0, 1, 10, 11}; I want to convert the

  • 0

I have:

uint8 buf[] = {0, 1, 10, 11};

I want to convert the byte array to a string such that I can print the string using printf:

printf("%s\n", str);

and get (the colons aren’t necessary):

"00:01:0A:0B"

Any help would be greatly appreciated.

  • 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-23T03:12:50+00:00Added an answer on May 23, 2026 at 3:12 am
    printf("%02X:%02X:%02X:%02X", buf[0], buf[1], buf[2], buf[3]);
    

    For a more generic way:

    int i;
    for (i = 0; i < x; i++)
    {
        if (i > 0) printf(":");
        printf("%02X", buf[i]);
    }
    printf("\n");
    

    To concatenate to a string, there are a few ways you can do this. I’d probably keep a pointer to the end of the string and use sprintf. You should also keep track of the size of the array to make sure it doesn’t get larger than the space allocated:

    int i;
    char* buf2 = stringbuf;
    char* endofbuf = stringbuf + sizeof(stringbuf);
    for (i = 0; i < x; i++)
    {
        /* i use 5 here since we are going to add at most 
           3 chars, need a space for the end '\n' and need
           a null terminator */
        if (buf2 + 5 < endofbuf)
        {
            if (i > 0)
            {
                buf2 += sprintf(buf2, ":");
            }
            buf2 += sprintf(buf2, "%02X", buf[i]);
        }
    }
    buf2 += sprintf(buf2, "\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How is the image data saved with an uint8 array? Say that I have
I have a byte array (say, UInt8 *somebuffer) with data in an unknown format.
I have a function uint8_t EE_Write(uint8_t addr, uint8_t len, uint8_t * buf) that takes
I have an 8x16 matrix of bits as a UINT8 matrix[16]. I want to
I have a jagged uint8 array like this in c++: UINT8 ras[2][3] = {{1,2,3},{4,5,6}}
in c++ I have such function extern C _declspec(dllexport) uint8* bufferOperations(uint8* incoming, int size)
I have an NSString like so: 850210 How can i convert it to uint8_t
I have class Phenotype with the following constructor: Phenotype(uint8 init[NUM_ITEMS]); I can create a
I have an image in Matlab: img = imopen('image.jpg') which returns an uint8 array
I have a std::vector<uint8_t> that contains strings at specific offsets. Here's a shortened dump:

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.