Copy a buffer to a bit field struct

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

Is there any way to copy a BYTE array to a bit field structure? Here is
an example of what I need...


typedef struct
{
BYTE field1 : 5;
BYTE field2 : 8;
BYTE field3 : 3;
} st;


st s;

BYTE buffer[2];

buffer[0] = 0x0D;
buffer[1] = 0x2D;


I want to copy or typecast buffer onto s...

s.field1 should be equal to 1 (binary 00001)
s.field2 should be equal to 165 (binary 10100101)
s.field3 should be equal to 5 (binary 101)


s = * ((st*) buffer) doesn't work since it sets s.field1 to 13, s.field2 to
45 and s.field3 to 0 (copies buffer[0] to field1 and buffer[1] to field2)


Thanks

Jeronimo
.



Relevant Pages

  • Re: Copy a buffer to a bit field struct
    ... > Is there any way to copy a BYTE array to a bit field structure? ... -- RFC 1925 ... Prev by Date: ...
    (microsoft.public.vc.language)
  • Re: typedef struct
    ... > I could understand typedef struct jmp_buf, ... It declares a jmp_buf as an array of 1 element of the given ... Prev by Date: ...
    (comp.lang.c)