1. ## bool variables

I have a vector of bool vals;
V1 = [0,1,0,1]
V2 = [1,0,0,1]
V3 = [1,1,1,1]
V4 = [0,0,0,1]

V1*V2 = [0,0,0,0]
V1*V3 = [0,1,0,1]
V1*V4 = [0,0,0,1]

what is fastest way to perform the following operation in C++

if V1*V2 = V1 then true else false?
if V1*V3 = V1 then true else false?
if V1*V4 = V1 then true else false?

is there a way to do it with addition/subtraction instead of multiplication?

when I do subtraction the -1 val become a true.

2. Multiplication can be done by &&. I do not know about faster or slower, but it makes more sense than multiplication where boolean values are concerned. (What does true multiplied by true mean?)

3. Do you really have to do this without multiplication? Have you actually seen that it is a bottleneck?

4. Generally, for boolean values, you use AND(&&) for multiplication, and XOR(!=) for addition, assuming the boolean is seen as integers modulo 2.

5. Originally Posted by Elysia
Do you really have to do this without multiplication? Have you actually seen that it is a bottleneck?
I don't even know how to do bottleneck testing, was just wondering if someone had some insight. how can i do that?

6. If you run your program, does it take long time to execute?
If yes, then you can use a profiler to find out where most of the time is spent. If the time is spent on your multiplication, then you can optimize it. Otherwise it's called premature optimization and that's never a good thing.