Is there a fast way to find if a 32-bit integer is a multiple of 4 without using the % operator (In C++)?
Share
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, there is.
Note that this may not be any faster. Also a good optimizing compiler will convert your modulus against constant 4 to the fastest operation anyway, so it may well generate this automatically.
Check the generated code if you are interested.