Re: The & Operator



Albert <albert.xtheunknown0@xxxxxxxxx> schrieb:

> And could someone give me an example of when the & operator is useful
> or needed?

I guess you mean a real-world example ...

Think of some code-base that uses for example the following definition
for error values to set or return:

// Error-categories
#define CAT_FILEOP 0x0100
#define CAT_WHATEVER 0x0200

#define ERR_NOSUCHFILE (CAT_FILEOP|0x01) // '|' means OR where '&' means AND
#define ERR_FILEEXISTS (CAT_FILEOP|0x02)

// ...

#define ERR_OUTOFMEM (CAT_WHATEVER|0x01)

Then you can use:

void check_error(int _err)
{
int cat,err;

cat = _err&0xf00; // mask out the specific error bits and get the category
err = _err&0x0ff; // mask out the category bits and get the error
hope("this helped"); // ;-)
}

Markus
.