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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:24:06+00:00 2026-06-05T20:24:06+00:00

I am looking into a method to convert a byte array to a hexadecimal

  • 0

I am looking into a method to convert a byte array to a hexadecimal string here is what i coded :

unsigned char buffer[] = {0xAA,0xBB,0x01,0xAB,0x11,0x12,0x13,0x22,0x11,0x14};


int _tmain(int argc, _TCHAR* argv[])
{

                char * asta = (char*)malloc(16);
                memset(asta,0,16);
                int k;
                for (k = 0; k < 16 ; k++)
                {
                    sprintf(&asta[k],"%X",buffer[4 + k]);
                }

                printf("%s",asta);

    _getch();
}

Only the first byte is converted correctly the rest are not. How can i fix the code ?

  • 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-05T20:24:08+00:00Added an answer on June 5, 2026 at 8:24 pm

    You have to remember that two-digit hexadecimal numbers will still be two digits when you print it as a string, i.e. it will take up two characters.

    In the loop, the second iteration will overwrite the second character of the string, the third iteration will overwrite the third characters, etc.

    Also, since each two-digit number will use two characters, you must allocate memory for 32 characters, plus one for the string terminating '\0' character.

    And as noted in the comments, you are accessing data outside of your array.

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

Sidebar

Related Questions

I Looking for a method that convert time string into Calendar look like this:
I am looking for method to convert array into ojbect in kohana I got
I am looking for a fastest method to convert one YUV array into RGBA
I'm looking for a method of turning a NSMutableArray into a string. Is there
Can we convert a byte array into an InputStream in Java? I have been
To convert an int into a byte array, I'm using the following code: int
Looking into org.pentaho.reporting.engine.classic.core.DataFactory and more specifically into the initialize method (which was formerly part
I am looking into catching every method that is defined on a base class,
I am looking into the jQuery UI Resizable method and I have to DIVs
In my custom view I'm looking into using Canvas.getClipBounds() to optimize my onDraw method

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.