Copy a buffer to a bit field struct
- From: Jeronimo Bertran <jeronimo.bertran@xxxxxxxxxxxxxxxx>
- Date: Mon, 24 Oct 2005 19:21:47 -0700
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
.
- Follow-Ups:
- Re: Copy a buffer to a bit field struct
- From: Tim Roberts
- Re: Copy a buffer to a bit field struct
- From: Igor Tandetnik
- Re: Copy a buffer to a bit field struct
- Prev by Date: Re: Where is the Microsoft C++ for Macintosh Compiler?
- Next by Date: Re: Copy a buffer to a bit field struct
- Previous by thread: Re: Where is the Microsoft C++ for Macintosh Compiler?
- Next by thread: Re: Copy a buffer to a bit field struct
- Index(es):
Relevant Pages
|