I am reviewing some C code, and found a header file full of defines of the style:
#define BLABLABLABLA (1 << 2)
#define XXXXXXXXXXXX (1 << 3)
#define YYYYYYYYYYYY (1 << 4)
What do they mean? What do they do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
<< is the shift operator in C.
So you define BLABLABLABLABLA by a zero value with a binary 1 shifted by 2 digits to the left.
The resulting value is then :
…00000100
You would normally do this do mask things.
So, say you have one status byte where every bit is a flag.
And if the 3rd bit is set, this means BLABLABLABLABLA, you would do :
int blablaFlag = statusByte & BLABLABLABLABLA;
If this is greater 0, your flag was set.