locked
How to convert a number of checkboxes to a List<List<bool>> RRS feed

  • Question

  • User-1771888428 posted

    How to obtain all states of n checkboxes to a List<List<bool>>, For example 5 checkboxes have 2^5 states, then convert this number (32) to its binary values in a list and finaly convert these binaries to a List<List<bool>>  

    [ 0b11111, 0b11110, 0b11100, ... ] => { {true,true,true,true,true}, {true,true,true,true,false}, {true,true,true,false,false}, ... }

    Tuesday, April 9, 2019 7:43 PM

All replies

  • User475983607 posted

    Use the shift operator.  I don't see any reason to convert to a List<bool> then a binary as the checkbox list is already a collection of I/O.

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/left-shift-operator

    Tuesday, April 9, 2019 8:27 PM
  • User-1771888428 posted

    Is it a way to obtain all of the alternations (combinations) of n bits in a List<List<bool>>?

    Wednesday, April 10, 2019 2:56 PM
  • User475983607 posted

    Is it a way to obtain all of the alternations (combinations) of n bits in a List<List<bool>>?

    This is a math question? A 5-bit number is 2^5 = 32.    I think you are asking about factorials but I'm not sure.  Anyway 32! = 2.6313083693369353016721801216 x 10^35.  And a  very large number.

    Wednesday, April 10, 2019 3:25 PM