D
Dave
I need to rewrite the following using shifts and masks for portability
sakes, and to get rid of the BYTE_ORDER issue.
/* CODE */
struct test {
#if BYTE_ORDER == BIG_ENDIAN
unsigned char ver:4;
unsigned char res1:4;
#else
unsigned char res1:4;
unsigned char ver:4;
#endif
unsigned char reserved2;
unsigned short checksum;
};
void
function(unsigned char *data)
{
struct test *t = (struct test *)data;
if (t.ver == 1) {
/* match */
}
}
/* END */
I was thinking I could just do the following, but it does not seem to work.
void
function(unsigned char *data)
{
uint32_t test = *(uint32_t *)data;
/* shift 28 bits, mask 4 */
if (((test >> 28) & 0x0f) == 1) {
/* match */
}
}
I am thinking the declaration is not correct.
Thanks for any help
- Dave
sakes, and to get rid of the BYTE_ORDER issue.
/* CODE */
struct test {
#if BYTE_ORDER == BIG_ENDIAN
unsigned char ver:4;
unsigned char res1:4;
#else
unsigned char res1:4;
unsigned char ver:4;
#endif
unsigned char reserved2;
unsigned short checksum;
};
void
function(unsigned char *data)
{
struct test *t = (struct test *)data;
if (t.ver == 1) {
/* match */
}
}
/* END */
I was thinking I could just do the following, but it does not seem to work.
void
function(unsigned char *data)
{
uint32_t test = *(uint32_t *)data;
/* shift 28 bits, mask 4 */
if (((test >> 28) & 0x0f) == 1) {
/* match */
}
}
I am thinking the declaration is not correct.
Thanks for any help
- Dave