I know how to convert an integer from decimal to fixed length binary string:
int number = 3;
int toBase = 2;
int length = 8;
Convert.ToString(number, toBase).PadLeft(length, '0')
Output:
00000011
How to assign the individual elements of that binary string to either int
(or bool
) array, such that after the conversion the array will look like1:
int[] binary = {0, 0, 0, 0, 0, 0, 1, 1}
or
bool[] binary = {false, false, false, false, false, false, true, true};
1. Using the facilities and not trivial for
loop with char
to int
(or bool
) type conversions.