-
March 11th, 2012, 03:35 PM
#1
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.
-
March 12th, 2012, 04:49 AM
#2
-
March 12th, 2012, 01:59 PM
#3
Re: PackedBits
Originally Posted by lch2
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...
-
March 13th, 2012, 01:17 PM
#4
Re: PackedBits
Pretty sure you will also need the extern "C" for this, because C++ will pad however it wishes.
-
March 16th, 2012, 02:42 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|