#define OUTGOING_MASK 0x0c
#define OUTGOING_DISABLED 0x04
#define OUTGOING_ENABLED 0x08
#define OUTGOING_AUTO 0x00
#define REFER_SUPPORTED 0x80
Assume support is some value of type int.
I have a getter function
int get()
{
if(OUTGOING_DISABLED == support & OUTGOING_MASK)
return 1;
else if(OUTGOING_ENABLED == support & OUTGOING_MASK)
return 2;
else if(OUTGOING_AUTO == support & OUTGOING_MASK)
return 3;
}
I need to write set function for this like
void set(int val)
{
if(val ==1)
//todo
else if(value == 2)
//todo
else if(value == 3)
//todo
}
How to write getter and setter functions for this?
I need to get/set the support variable here
REFER_SUPPORTED will always be set in support.
You can’t recover value of b, unless a has ALL bits set. “&” is irreversible.
Explanation. & operation has following table:
which means, to recover b, you could try to use following table:
As you can see it isn’t possible to guess b in all cases.
In expression a & b = c, if you know c and a, you can’t recover b, because for every zeroed bit of c, and if corresponding bit of a is also zero, there are two possible states of corresponding bits of b. You can reliably recover b only if every bit of a is set to 1.