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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:10:39+00:00 2026-05-24T02:10:39+00:00

Is there any command in stl that converts ascii data to the integer form

  • 0

Is there any command in stl that converts ascii data to the integer form of its hex representation? such as: “abc” -> 0x616263.

i have the most basic way i can think of:

uint64_t tointeger(std::string){
    std::string str = "abc";
    uint64_t value = 0;                  // allow max of 8 chars
    for(int x = 0; x < str.size(); x++)
        value = (value << 8) + str[x];
    return value;
}

as stated above: tointeger("abc"); returns the value 0x616263

but this is too slow. and because i have to use this function hundreds of thousands of times, it has slowed down my program significantly. there are 4 or 5 functions that rely on this one, and each of those are called thousands of times, in addition to this function being called thousands of times

what is a faster way to do this?

  • 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-24T02:10:41+00:00Added an answer on May 24, 2026 at 2:10 am

    You want to pack ASCII characters from a string into a 64-bit integer.

    Since std::string is not an intrinsic type, for safety, copy the data into a buffer:

    uint_64 values[100]; // Allocate memory on a 64-bit boundary.
    
    char * p = (char *) values; // Point to the memory as characters.
    
    std::string example("beethoven");
    
    std::copy(example.c_str(), p, example.length();
    

    The copying is more safe as far as alignments go. To be faster, but more dangerous, just avoid the copy:

      uint_64 danger;
      danger = *((uint_64 *) example.c_str());
    

    The std::string::c_str method returns a pointer to a c-style string representation of the text, but the text is not guaranteed to last forever, thus the need to copy. Also, the pointer is only guaranteed to be on a character alignment. Thus if it happens to reside at address 0x1003, the processor may generate an alighnment fault (or slow down because it has to fetch at an un-aligned boundary).

    Edit 1:

    This method does not take into consideration Endianness. The method uses the Endianness of the platform. Changing Endianness will slow the performance.

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

Sidebar

Related Questions

Is there any command that I can locate a certain table from all databases?
Is there any command in vim with which I can jump to an already
Is there any command using which we can inspect a object in command line
In commit messages there is a rule which says: Lines starting with '#' will
I have a Oracle backup done with EXP utility. How can I validate it?
I want to find out storage usage of an app. I can list file
I am new to Windbg and trying to understand a few things about value
I am looking for a clean, well-built CMS. I want to migrate a number
New to maven and equinox. While going through a tutorial on OSGi, I issued
I am using C language and Linux OS as my programming platform. And I

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.