CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: PackedBits

  1. #1
    Join Date
    May 2011
    Posts
    23

    PackedBits

    I have a incoming packet of 75 bytes. It is packed of five 10 Bitters and five 5 Bitters. like 10-5-10-5-... What is the best way to receive-parse-modify and send the packet back using struct/union or any ther way.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: PackedBits

    Quote Originally Posted by lch2 View Post
    I have a incoming packet of 75 bytes. It is packed of five 10 Bitters and five 5 Bitters. like 10-5-10-5-... What is the best way to receive-parse-modify and send the packet back using struct/union or any ther way.
    What is a "10 Bitter"? 10-bit value? Packed into what?
    Trying to figure out your math. If you have five 10-bit values and five 5-bit - this only makes 75 BITS, not bytes. What am I doing wrong?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Jan 2009
    Posts
    1,689

    Re: PackedBits

    Pretty sure you will also need the extern "C" for this, because C++ will pad however it wishes.

  5. #5
    Join Date
    Mar 2004
    Location
    Central Florida
    Posts
    293

    Re: PackedBits

    No, he won't need to extern it. C++ will not pad it if he builds his struct properly.

    Code:
    struct SomeBits
    {
        unsigned short first_10_bits : 10;
        unsigned char next_5_bits : 5;
        unsigned short next_10_bits : 10;
        unsigned char next_5_bits : 5;
        unsigned short next_10_bits : 10;
        unsigned char next_5_bits : 5;
        unsigned short next_10_bits : 10;
        unsigned char next_5_bits : 5;
        unsigned short next_10_bits : 10;
        unsigned char next_5_bits : 5;
        unsigned char pad :5;
    Always try to allign your packed structs on word boundries, at the very least.
    "Effective teaching is the essence of leadership..."

    "There is no substitute for a carefully thought-out design."

    If you have found this post to be useful, please Rate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured