I have a question about bit operation in c++,
there is a set of code:
#define INDEX(SRC, DEST) ((U16)SRC | (DEST << 8))
what does this (U16)SRC | (DEST << 8) means?
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.
I would guess U16 is also a macro somewhere in the code and it probably designates a 16-bit unsigned integer type(which I deduce from the abbreviation). SRC and DST are the two arguments to the macro expansion the code is defining and (U16)SRC | (DEST << 8) would mean that DEST gets bit shifted 8 bits to the left and then logical or-ed to SRC. Probably the code depends that both SRC and DEST are 8-bit values and this code creates a bit mask that is the result of the appending of the 8-bits of DEST to the 8-bits of SRC.
For instance if (in binary) DEST is 10010101 and SRC is 00001111 then the result is 1001010100001111.