LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a string of numbers into an array of booleans

just mod 2 each integer. Use the remainder as your answer. Then convert to Boolean

0 Kudos
Message 11 of 20
(896 Views)

 

Research the "String To Byte Array" function.

Also Auto indexing For Loop. 

 

Also think about the fact that ASCII Codes 48 50 52 54 56 for the string char '0','2','4','6','8' are even

and the ASCII Codes 49 51 53 55 57 for the string char '1','3','5','7','9' are odd.

 

You could use "Quotient & Remainder" but if you understand binary representation of numbers, the bit shift function "Rotate Right With Carry" and the Not function would be another opptions.

 

Post back what you have come up with. 

Omar
0 Kudos
Message 12 of 20
(893 Views)

Well, you could convert it to a byte array and immedately convert it to a single-character array to be processed. 😄

 

The nice thing about ASCII representation of numbers is that even/odd matches between value and code. 😉

0 Kudos
Message 13 of 20
(890 Views)

Along altenbach's line of thought, i can get it using 4 primitives and no for loop.  I too have a hard time thinking in terms of bits but exercises like this help. Smiley Happy

aputman
0 Kudos
Message 14 of 20
(878 Views)

This is the LabVIEW's version of "I Can Name That Tune in 3 notes".

 

I can code that in 4 nodes

 

I too go with altenbach's solution


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


 

"String To Byte Array" function

"And" function

"Equal to 0?" function

and a U8 constant

Boolean array indicator

Omar
0 Kudos
Message 15 of 20
(867 Views)

@Omar_II wrote:

This is the LabVIEW's version of "I Can Name That Tune in 3 notes".

 

I can code that in 4 nodes

 

I too go with altenbach's solution


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


 

"String To Byte Array" function

"And" function

"Equal to 0?" function

and a U8 constant

Boolean array indicator


 

You could have at least mixed up the order of the nodes so as not to give it away.  Smiley Very Happy  Also, as a beginner Labview programmer, the OP should probably not turn in this method as the solution....may look suspicious to professor.

aputman
0 Kudos
Message 16 of 20
(855 Views)

aputman wrote:

 

Also, as a beginner Labview programmer, the OP should probably not turn in this method as the solution....may look suspicious to professor.


As a professor I would ask about each step and how they figured out that those set of steps produced the right outcome.  If they could tell me how they did it I would start asking much harder questions.

0 Kudos
Message 17 of 20
(849 Views)

Ok, I figured it outSmiley Happy.  I converted the string to an unsigned byte, which I then auto-indexed into a for loop.  I then used the quotient and remainder function and modded each element by 2.  I then used a case structure.  I set 1 as the default, which output false, and had 0 output true.  I then auto-indexed this out of the loop and put a boolean indicator.  P.S. This was only a small part of a bigger assignment.  Part of the problem was that another part of my code was messing everything up.  Thank you so much for the help!

0 Kudos
Message 18 of 20
(831 Views)

@vikingsfan345 wrote:

Ok, I figured it outSmiley Happy.  I converted the string to an unsigned byte, which I then auto-indexed into a for loop.  I then used the quotient and remainder function and modded each element by 2.  I then used a case structure.  I set 1 as the default, which output false, and had 0 output true.  I then auto-indexed this out of the loop and put a boolean indicator.  P.S. This was only a small part of a bigger assignment.  Part of the problem was that another part of my code was messing everything up.  Thank you so much for the help!


That sounds way too complicated 😄

 

Try to simplify it! (e.g. replace the case structure with an "=0", then "right-click...remove" the FOR loop. :D)

0 Kudos
Message 19 of 20
(825 Views)

@altenbach wrote:

@vikingsfan345 wrote:

Ok, I figured it outSmiley Happy.  I converted the string to an unsigned byte, which I then auto-indexed into a for loop.  I then used the quotient and remainder function and modded each element by 2.  I then used a case structure.  I set 1 as the default, which output false, and had 0 output true.  I then auto-indexed this out of the loop and put a boolean indicator.  P.S. This was only a small part of a bigger assignment.  Part of the problem was that another part of my code was messing everything up.  Thank you so much for the help!


That sounds way too complicated 😄

 

Try to simplify it! (e.g. replace the case structure with an "=0", then "right-click...remove" the FOR loop. :D)


Ok, that makes sense.  Thanks.

0 Kudos
Message 20 of 20
(811 Views)