Let’s say I want to bit shift i twice to the left and store the value in f.
f = i << 2;
Is that correct? How exactly do I do this in C/C++?
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.
Yes.
Shifts are useful in a number of bit twiddling operations.
This used to be a great way to multiply a number by four. However, these days, optimizing compilers tend to take care of that for you.
Keep in mind that the two leftmost bits are discarded.