Optimize integer multiplication with +/-1
Optimize integer multiplication with +/-1 Is it possible to optimize multiplication of an integer with -1/1 without using any multiplication and conditionals/branches? Can it be done only with bitwise operations and integer addition? Edit : The final goal is to optimize a scalar product of two integer vectors, where one of the vectors has only -1/1 values. Like this: i = ~i + 1; ? – alk Jul 1 at 9:32 i = ~i + 1; your suggestion negates the number with 2's completement but where is the condition (1, -1) ? – Jean-François Fabre Jul 1 at 9:35 Reading yours comments, I feel I somehow did not got the question. – alk ...