LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a string of numbers into an array of booleans

For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

0 Kudos
Message 1 of 20
(3,417 Views)

@vikingsfan345 wrote:

For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?


Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 20
(3,410 Views)

@billko wrote:

Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier.  🙂


I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.

0 Kudos
Message 3 of 20
(3,395 Views)

@Hooovahh wrote:

@billko wrote:

Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier.  🙂


I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.


LOL maybe that was one of the objectives of the homework.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 20
(3,392 Views)

A bitwise AND with a special number is typically simpler. Try to figure it out.

0 Kudos
Message 5 of 20
(3,387 Views)

@billko wrote:

@Hooovahh wrote:

@billko wrote:

Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier.  🙂


I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.


LOL maybe that was one of the objectives of the homework.  😉


To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  

 

It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.

0 Kudos
Message 6 of 20
(3,384 Views)

@altenbach wrote:

A bitwise AND with a special number is typically simpler. Try to figure it out.


I always forget about how to do things bitwise.  My mind just refuses to think like that.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 20
(3,382 Views)

Ok, I see what you guys are saying with regards to the quotient and remainder function.  I'm mainly stumped on converting each character in the string of numbers into a number.  I know that there is a function called, "Decimal String to Number," which I tried using, but with no success.  I'm thinking that I'll probably have to convert the entire string into one big number, and then from there I will be able to select each individual number.  Any tips on converting the string of numbers into a number (or converting each character into a number if that will work)?

0 Kudos
Message 8 of 20
(3,376 Views)

Just convert to a U8 array and autoindex over it. You could use a LUT for even/odd You could even do it completely loop-free 😄

0 Kudos
Message 9 of 20
(3,373 Views)

@altenbach wrote:

Just convert to a U8 array and autoindex over it. You could use a LUT for even/odd You could even do it completely loop-free 😄


I'm not sure how many new programmers to LabVIEW know much about the ASCII table, which is what that U8 array will be.  While you come up with the better solution for the situation, I feel like that type of method will confuse new users.

 

You may have better luck if you process each string character one at a time, rather then trying to convert the whole string at once, and then get each digit.

0 Kudos
Message 10 of 20
(3,364 Views)