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

The Archive Base Latest Questions

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

I hope the title is describing the problem, i’ll change it if anyone has

  • 0

I hope the title is describing the problem, i’ll change it if anyone has a better idea.

I’m storing information in a struct like this:

struct AnyStruct
{
    AnyStruct() :
        testInt(20),
        testDouble(100.01),
        testBool1(true),
        testBool2(false),
        testBool3(true),
        testChar('x') {}

    int testInt;
    double testDouble;
    bool testBool1;
    bool testBool2;
    bool testBool3;
    char testChar;

    std::vector<char> getBinaryBlock()
    {
        //how to build that?
    }
}

The struct should be sent via network in a binary byte-buffer with the following structure:

Bit 00- 31: testInt
Bit 32- 61: testDouble most significant portion
Bit 62- 93: testDouble least significant portion
Bit     94: testBool1
Bit     95: testBool2
Bit     96: testBool3
Bit 97-104: testChar

According to this definition the resulting std::vector should have a size of 13 bytes (char == byte)

My question now is how I can form such a packet out of the different datatypes I’ve got. I’ve already read through a lot of pages and found datatypes like std::bitset or boost::dynamic_bitset, but neither seems to solve my problem.

I think it is easy to see, that the above code is just an example, the original standard is far more complex and contains more different datatypes. Solving the above example should solve my problems with the complex structures too i think.

One last point:
The problem should be solved just by using standard, portable language-features of C++ like STL or Boost (

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

    I’ve now used the std::bitset for generating bit-sequences for the datatypes and then concatenated these bitsets to one big bitset.
    This then holds the data I need. I just have to check for little/big endian.

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

Sidebar

Related Questions

(I hope this is a valid question) As I stated in my title, I'm
I'm not even sure about how to title this qn. But, hope there is
I hope the title of this question is somewhat clear, I couldn't figure out
ok, I hope the title of this question makes sense. In my app I
I hope this is the appropriate title for this question. Right now I have
I hope the title of this question makes sense. What I want to know
I hope this title makes sense - I need case-insensitive regex matching on BlackBerry
I hope the title did not mislead you. My problem is the following: Currently
I hope the title isn't too confusing, I'll try to explain better below. Suppose
I hope the title is clear. I would like to retrieve the existing google

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.