Is there any performance loss/gain using bitset in place where hand written?
How to build the following using a bitset at runtime
- make all the bits between 2 and 5 as zero i.e.,
11110011.
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.
The easiest solution to your second question would be to use another bitset.
It takes a bit of math to come up with an expression for
maskgiven two bit positions.[edit]
Ok, here’s the math. The trick is that
(1UL << X) -1is a sequence ofXones. E.g. 3 => 00000111.Hence, (1<<5) – (1<<3) = 00011111 – 00000111 -1 + 1 = 00011000 (bits 3 and 4). Thus in code: