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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:55:21+00:00 2026-06-05T03:55:21+00:00

I have a problem with parsing the contents of a char[]. It contains bytes,

  • 0

I have a problem with parsing the contents of a char[]. It contains bytes, that can be formated as ASCII stings. The last two bytes however are CRC. Therefore I interpret everything but the last two entries in the array in hex to string:

std::ostringstream payload;
std::ostringstream crc;
payload << std::hex;
crc << std::hex;

// last two bytes are CRC
for (int i = 0; i < this->d_packetlen - 2; i++)
  {
  payload << static_cast<unsigned>(this->d_packet[i]);

     for (int j = i; j < this->d_packetlen; i++)
       {
         crc << static_cast<unsigned>(this->d_packet[j]);
       }
}
std::string payload_result = payload.str();
std::string crc_result = crc.str();

fprintf(d_new_fp, "%s, %s, %d, %d\n", payload_result.c_str(),
   crc_result.c_str(), this->d_lqi, this->d_lqi_sample_count);

This doesn’t work, and I’m not sure why that is? Is there an easier way to cast unsinged chars to ASCII?

Best,
Marius

  • 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-05T03:55:23+00:00Added an answer on June 5, 2026 at 3:55 am

    This is an infinite loop:

    for (int j = i; j < this->d_packetlen; i++)
    {
       crc << static_cast<unsigned>(this->d_packet[j]);
    }
    

    In this loop, you are NOT incrementing j; instead you’re incrementing i. Maybe, that is the problem?


    Also, the way you’ve described the problem, I think the correct solution is this:

    for (int i = 0; i < this->d_packetlen - 2; i++)
    {
      payload << static_cast<unsigned int>(this->d_packet[i]);
    }
    for (int j = this->d_packetlen - 2; j < this->d_packetlen; j++)
    {
       crc << static_cast<unsigned int>(this->d_packet[j]);
    }
    

    That is the second loop should be outside the first loop.

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

Sidebar

Related Questions

I have a problem parsing a XML file which contains special characters like ,
I have this JSON file (the parsing OK, the problem is displaying the contents
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my
Ok, I have a very frustrating problem. I am parsing a webpage and need
I have a problem with message parsing on WCF service. I ran server-side of
I have a CSV file that contains over 80,000 rows and 100 columns. I'm
Already i have worked on SBJSON parsing, that was working very fine. Now, i
I have this strange problem parsing XML document in PHP loaded via cURL. I
I have problem with parsing XML. I parsed data of cities, Amsterdam & Den
I have a problem with an app that takes an XML feed, parses it,

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.