# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Convert a long string into a Boolean array

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

Message 1 of 7
(289 Views)
Solution
Accepted by topic author Anupama07

## Re: Convert a long string into a Boolean array

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

Jim
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
(279 Views)
Solution
Accepted by topic author Anupama07

## Re: Convert a long string into a Boolean array

Hi Anupama,

more possible (Rube-Goldberg-ish) ways:

Best regards,
GerdW

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

## Re: Convert a long string into a Boolean array

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.

Message 4 of 7
(216 Views)

## Re: Convert a long string into a Boolean array

Ok. thanks a lot.

Message 5 of 7
(190 Views)

## Re: Convert a long string into a Boolean array

Ok..Thanks a lot.

Message 6 of 7
(189 Views)

## Re: Convert a long string into a Boolean array

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.

Message 7 of 7
(182 Views)