04-02-2024 07:02 AM
I have a 23 characters long string that I have read from a file (e.g: 11110000101011110000101 ). How can i convert this into a Boolean array
Solved! Go to Solution.
04-02-2024 07:16 AM
04-02-2024 07:50 AM - edited 04-02-2024 07:56 AM
04-02-2024 09:19 AM
First of all, 23 characters is not "long", even a typical integer has more bits than that!
You already got obvious solutions that must assume that the string is clean. To make it bulletproof, you need to make sure that an error is generated if there is any character that is not 0, or 1 *e.g. if there is a linefeed at the end, for example). Assuming these are "bits", you also need to define if the LSB should be the first or last element of the boolean array. Can you guarantee that there are always exactly 23 characters?
Even a boolean array is relatively boring. Can you give us some context on how it is used later? If it is just an intermediary to some algorithm, maybe you don't even need it.
04-02-2024 01:06 PM
Ok. thanks a lot.
04-02-2024 01:06 PM
Ok..Thanks a lot.
04-02-2024 01:10 PM
Yes. It's always 23 bits. The bit sequence is written in the file in the correct order and the program will take the bit sequence in the correct order and further process it. Thank you.