I have an integer number withing an interval [0,7]. And I want to convert this number into a Boolean list with 3 elements with Java.
1st element in the list has a value of 4, 2nd element has 2 and 3rd element is 1. Their sum makes 7 if all the elements in the list are "true". "False" has a value of 0.
Here are the all possibilities:
If the number is 7 my boolean list is [true, true, true]
If the number is 6 my boolean list is [true, true, false]
If the number is 5 my boolean list is [true, false, true]
If the number is 4 my boolean list is [true, false, false]
If the number is 3 my boolean list is [false, true, true]
If the number is 2 my boolean list is [false, true, false]
If the number is 1 my boolean list is [false, false, true]
If the number is 0 my boolean list is [false, false, false]
I don't want to code this with 8 else if blocks. I think there must be a smarter solution with combinations of the numbers.
Here is my function declaration: default List<Boolean> convertIntToBooleanList(int i);
Do you have any ideas how can I solve it without hardcoding?
Thanks!