unsigned long long n = 0;
for (int i = 0; i <= 64; i+=2)
n |= 1ULL << i; //WHAT DOES THIS DO? AH!
I’m trying to wrap my head around what the third line of this code actually does. Someone please help clear this up!
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.
That line sets the ith bit of n.
1ULLis the integer 1 with type unsigned long long.<<is a bitshift operator.1ULL << iis equal to 2i, or in binary:100...0with i zeros.n |= x;is a compound assignment operator. It is similar to writingn = n | x;.|is the bitwise OR operator.Wikipedia has an example showing how bitwise OR operator works in the general case:
Related