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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:25:09+00:00 2026-05-17T15:25:09+00:00

I have a large hex string abcdef… and I want to convert it to

  • 0

I have a large hex string

abcdef...

and I want to convert it to

0xab 0xcd 0xef 

Are there any functions that do that?

Also could you tell me what I means when people ask are those inputs in ASCII or not?
abcdef are represented as a string. Not sure if that is ASCII or not. not sure what they mean. I am very new to programming so help here would be appreciated. I have a huge string that I need to use in my array and converting it into the aforementioned format will help me initialize my array with the hex string.

  • 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-17T15:25:09+00:00Added an answer on May 17, 2026 at 3:25 pm

    You can do this using string streams.

    #include <iostream>
    #include <sstream>
    #include <vector>
    
    int main( int , char ** )
    {
      const char *str = "AFAB2591CFB70E77C7C417D8C389507A5";
      const char *p1  = str;
      const char *p2  = p1;
    
      std::vector<unsigned short> output;
    
      while( *p2 != NULL ) {
        unsigned short byte;
    
        ++p2;
        if( *p2 != NULL ) {
          ++p2;
        }
    
        std::stringstream sstm( std::string( p1, p2 ) );
    
        sstm.flags( std::ios_base::hex );
        sstm >> byte;
    
        output.push_back( byte );
    
        p1 += 2;
      }
    
      for( std::vector<unsigned short>::const_iterator it = output.begin(); it != output.end(); ++it ) {
        std::cout << std::hex << std::showbase << *it << "\t" << std::dec << std::noshowbase << *it << "\n";
      }
    
      std::cout << "Press any key to continue ...";
      std::cin.get();
    }
    

    Note that if you use unsigned char instead of unsigned short the conversion from stringstream attempts to convert it into an ASCII character and it doesn’t work.

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

Sidebar

Related Questions

I have a javascript rich page that is passing a large JSON formatted to
I have large JSP page, and there is XML creation on it. For debug
I have a 128-bit number in hexadecimal stored in a string (from md5, security
I have a large and unique integer (actually a SHA1 hash). Note: While I'm
I have large MySQL tables with hundreds of thousands of rows. I need to
I have large matrix, 4000x4000 I need to calculate local average of 11x11 window
Inspired by the top answer on this page I wrote a python program to
I am writing a number converter between the (b h d) numbering systems ,
i'm trying to get back a style property in all valid 'length' and 'percent'

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.