Showing results for 
Search instead for 
Did you mean: 

Convert a long string into a Boolean array

Go to solution

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 

0 Kudos
Message 1 of 7
Accepted by topic author Anupama07

You could convert the string to a byte array and compare with 49 (ASCII "1").




You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 2 of 7
Accepted by topic author Anupama07

Hi Anupama,


more possible (Rube-Goldberg-ish) ways:


Best regards,

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7

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.

0 Kudos
Message 4 of 7

Ok. thanks a lot.

0 Kudos
Message 5 of 7

Ok..Thanks a lot.

0 Kudos
Message 6 of 7

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.

0 Kudos
Message 7 of 7