How to perform a bitwise only (shifts,and,or,xor..) round up to even numbers if the number is odd (also for negative numbers)?
Example:
- Input: 3; Output: 4
- Input: 4; Output: 4
- Input: 5; Output: 6
- Input: 6; Output: 6
- Input: -14; Output: -14
- Input: -15; Output: -14
What I tried: This works so far, but it seems to be kinda redundant?
(((n + 1) >> 1) << 1)
Is there a shorter solution?