LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to decode a long string into individual digits and then sort into boolean

Basically my job is to take a long string that is just a big list of digits with no commas or spaces in between values into an array of Booleans using the fact that an even number represents a Boolean 'True' and an odd represents a 'False'. I know that to start I must have a format string for a scan from string that gives me each individual number from the length of 65,000 so that I can then put it through a case statement that compares it to odd or even and then put that in a Boolean array. The problem is I don't know what format string I should use to get each individual digit. I've attached the string that I want to convert into Boolean below.

0 Kudos
Message 1 of 5
(849 Views)

 


You have asked the question wrong...


@gch8244 wrote:

The problem is I don't know what format string I should use to get each individual digit. I've attached the string that I want to convert into Boolean below.


 

Have you thought about using String Subset?

 

String Even or Odd.png

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 2 of 5
(841 Views)

How about a little out-of-the-box thinking here.  You could just use the bytes directly.  Use String To Byte Array.  The values will show up between 0x30 (48) and 0x39 (57).  Notice that the even numbers will still have even values.  So you can just AND with 1 and a simple comparison and you now have an array of Booleans.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 5
(839 Views)

How would I then convert that array into an array of 8-bit numbers by using 8 boolean
bits at a time, i.e., the first 8 booleans give a single unsigned 8-bit integer, the next 8 booleans gives the second unsigned 8-bit integer, and so on. The array will thus be reduced in size by a factor of 8. 

0 Kudos
Message 4 of 5
(809 Views)

Hi gch,

 


@gch8244 wrote:

How would I then convert that array into an array of 8-bit numbers by using 8 boolean
bits at a time, i.e., the first 8 booleans give a single unsigned 8-bit integer, the next 8 booleans gives the second unsigned 8-bit integer, and so on. The array will thus be reduced in size by a factor of 8. 


You need to use the ReshapeArray function, followed by an autoindexing FOR loop with a BooleanArrayToNumber function inside…

It's really esay!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 5
(798 Views)