Re: The & Operator
- From: Markus Becker <yetispamb@xxxxxx>
- Date: Sat, 31 Dec 2005 02:55:15 +0100
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
.
- References:
- The & Operator
- From: Albert
- Re: The & Operator
- From: Albert
- The & Operator
- Prev by Date: Re: How to stop reading a file?
- Next by Date: Re: Structure size and binary format
- Previous by thread: Re: The & Operator
- Next by thread: Re: The & Operator
- Index(es):