D
Dave
Hello -
Say I have a 32 bit value in data (v:4, r:4, l:8, p:16)
[ v | r | l | p ]
unsigned char data;
Now, for portabilities sake, I want to use shifts and masks to access
these fields, instead of accessing the bitfields directly.
Lets assume v has a value of 2. To view the value of v in data, I need
to right shift 28 bits (correct?). How do I figure out what the MASK
should be?
#define MASK 0xff
if ((data & MASK) >> 28 == 2) {
/* matches */
}
I am having trouble understanding how to come up with masks. What would
the masks be for r, l, and p?
Thanks
Dave
Say I have a 32 bit value in data (v:4, r:4, l:8, p:16)
[ v | r | l | p ]
unsigned char data;
Now, for portabilities sake, I want to use shifts and masks to access
these fields, instead of accessing the bitfields directly.
Lets assume v has a value of 2. To view the value of v in data, I need
to right shift 28 bits (correct?). How do I figure out what the MASK
should be?
#define MASK 0xff
if ((data & MASK) >> 28 == 2) {
/* matches */
}
I am having trouble understanding how to come up with masks. What would
the masks be for r, l, and p?
Thanks
Dave