dimanche 19 mars 2017

Reducing an integer to 1 if it is not equal to 0

I'm trying to solve a timing leak by removing an if statement in my code but because of c++'s interpretation of integer inputs in if statements I am stuck.

The original code is:

int s if (s) r = A else r = B

Now I'm trying to rewrite it as:

int s; r = sA+(1-s)B

Because s is not bound to (0,1) I run into a problem at the (1-s)B part. What can I do, without using an if-statement on s to solve this?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire