Need some help regarding data structures
Hi all!
I need some help regarding the following problem.
I have 6 bytes of data in the following order:
Code:
head = 2 bits
data_base[32-30] = 3 bits
pause_bit = 1 bit
data_base[29-15] = 15 bits
pause_bit = 1 bit
data_base[14-0] = 15 bits
pause_bit = 1 bit
data_extent = 9 bits
pause_bit = 1 bit
I want to determine the data_base data. data_base has 33 bits, allocated
non contiguously in the six bytes.
So far, I have tried the following type of data structures:
Code:
typedef struct{
// byte 1
unsigned char head:2;
unsigned char data_base32-30:3;
unsigned char pause_bit1:1;
unsigned char data_base29_28:2;
// byte 2
unsigned char data_base27_20;
// byte 3
unsigned char data_base19_15:5;
unsigned char pause_bit1:1;
unsigned char data_base14_13:2;
// byte 4
unsigned char data_base12_5;
// byte 5
unsigned char data_base4_0:5;
unsigned char pause_bit1:1;
unsigned char data_extent8_7:2;
// byte 6
unsigned char data_extent6_0:7;
unsigned char pause_bit1:1;
}Mydata;
....
Mydata dData;
memcpy( &dData, address, sizeof(Mydata) );
With the above code, I was hoping to get the data_base bits correctly.
It doesnt work and I can't figure out why?
After getting the data_base bits seperately, I plan to use << and >> operators
to determine data_base.
I want to know if there is an easy way to determine data_base.
Thanks for helping.
Mas