# I need to group several optimizable inputs into a single input.

Maybe you could do something like this (untested/uncompiled):

bool lookup[3,8] = { { 0, 0, 0, 1, 0, 1, 1, 1 }, { 0, 0, 1, 0, 1, 1, 0, 1 }, { 0, 1, 0, 0, 1, 0, 1, 1 } }; int varSingle = 0; // Some value 0 to 7 bool var1 = lookup[ 0, varSingle ], var2 = lookup[ 1, varSingle ], var3 = lookup[ 2, varSingle ];

**Marco Antonio Colognese:**

varSingle | Var1 | Var2 | Var3 |
---|---|---|---|

0 | 0 | 0 | 0 |

1 | 0 | 0 | 1 |

2 | 0 | 1 | 0 |

3 | 1 | 0 | 0 |

4 | 0 | 1 | 1 |

5 | 1 | 1 | 0 |

6 | 1 | 0 | 1 |

7 | 1 | 1 | 1 |

Thank you in advance for your help!

You need to use a Switch statement not IF, to use case arguments

switch (varSingle ) { case 1: var1=false; var2=false; var3=true; break; case 2: var1=false; var2=true; var3=false; break; case 3: var1=true; var2=false; var3=false; break; case 4: var1=false; var2=true; var3=true; break; case 5: var1=true; var2=true; var3=false; break; case 6: var1=true; var2=false; var3=true; break; case 7: var1=true; var2=true; var3=true; break; default: var1=false; var2=false; var3=false; break; }

**Marco Antonio Colognese #:**

**Yes. I was wrong when I wrote here. Thanks for letting me know. But the doubt remains, as I would like a more efficient way for many boolean variables.**

You seem to have overlooked my post with a suitable option.

- 2022.03.11
- www.mql5.com

**Marco Antonio Colognese:**Being that it would be the equivalent of all the possible possibilities, as in the following table.

varSingle | Var1 | Var2 | Var3 |
---|---|---|---|

0 | 0 | 0 | 0 |

1 | 0 | 0 | 1 |

2 | 0 | 1 | 0 |

3 | 1 | 0 | 0 |

4 | 0 | 1 | 1 |

5 | 1 | 1 | 0 |

6 | 1 | 0 | 1 |

7 | 1 | 1 | 1 |

void decompose(int single, bool& var1, bool& var2, bool& var3){ var3 = single & 1 != 0; var2 = single & 2 != 0; var1 = single & 4 != 0; }

Otherwise the lookup table is likely the best.

**William Roeder #:**

Your decomposition is just binary, except for 3 and 4, and 5 and 6. Is that intentional? If not just mask the bits.

Otherwise the lookup table is likely the best.

I don't know if I understand your question as I'm using google translator! 😅

But they're all boolean variables, so they're all binary.

And I need all possibilities, from all variables off, to all on.

In the example I posted, I put 3 variables to exemplify, which I meant, so serial only 8 possibilities, (2^3) ("binary variable" ^ "three variables").

But if it is, for example, 10 binary variables, there would be 1024 possibilities.

Can you explain your suggestion better?

**Marco Antonio Colognese #:**Your solution so far is the most viable. However, in a case with 10 or more variables it would be complicated, as 10 rows and more than 500 columns would be needed.

Then I would suggest you look for the binary patterns so as to convert them into binary bit masking and/or shifting, just as William suggested in his post.

If however, there is no discernable pattern that can be converted, then my option of using a lookup table is still the most viable (and also the fastest).

EDIT: You can also load the lookup table from an external data file as well.

- 2022.03.11
- www.mql5.com

But how to make this conversion?

After normalizing so that the number of digits is equivalent to the number of variables,

then extracting the digit equivalent to the respective variable,

and finally transforming this information into boolean, is beyond my knowledge. 😅

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use

Good night.

I have the following demand, where I need help.

I have several boolean variables, which I would like to summarize to an int variable in an easier way than the example below, after all there are dozens of variables.

For example:

Being that it would be the equivalent of all the possible possibilities, as in the following table.

Thank you in advance for your help!