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

  • Home
  • SEARCH
  • 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 8884501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:04:29+00:00 2026-06-14T21:04:29+00:00

I have a hex string and want to convert this to a hex unsigned

  • 0

I have a hex string and want to convert this to a hex unsigned char array!

std::string hex = "0c45a1bf"

unsigned char hexCh = ""
    [0] = "0c"
    [1] = "45"
    [2] = "a1"
    [3] = "bf"

I want this bevavior shown in hexCh!

Best way over stringstream and std::hex? Have you an implementation?!

Thx

  • 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-14T21:04:30+00:00Added an answer on June 14, 2026 at 9:04 pm

    A possible solution: (thx Denis Ermolin):

    void ClassA::FuncA(unsigned char *answer)
    {
        std::string hex = "0c45a1bf";
        std::stringstream convertStream;
    
        // if you have something like "0c 45 a1 bf" -> delete blanks
        hex.erase( std::remove(hex.begin(), hex.end(), ' '), hex.end() );
    
        int offset = 0, i = 0;      
        while (offset < hex.length()) 
        {
            unsigned int buffer;
    
            convertStream << std::hex << hex.substr(offset, 2);         
            convertStream >> std::hex >> buffer;
    
            answer[i] = static_cast<unsigned char>(buffer);
    
            offset += 2;
            i++;
    
            // empty the stringstream
            convertStream.str(std::string());
            convertStream.clear();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hex string like: data = 437c2123 I want to convert this
I have a string that looks like this 7a and I want to convert
I have a hex string and i want to convert it utf8 to insert
I have a string that has 0111111100000000000000000000101 I wanted to convert this to hex,
Say that I have a 4 character string, and I want to convert this
I have a large hex string abcdef... and I want to convert it to
I have a string x that I need to convert into a hex format:
Let's say that I have a string 5a . This is the hex representation
I have this for example: 0 10000101 00111100000000000000000 and want to convert this to
I have a NSString with string like hello. Now I want to convert the

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.