LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to 1 and 0

Hi,, how can I convert a string constant containing 1 and 0 to 1 and zero

for example if the string is 1010000 then the it should be converted to 1010000 in (0,1) format. Somthing like Boolean array to (0,1) block

 

Thanks 

0 Kudos
Message 1 of 7
(3,123 Views)

Try the Scan From String function with "%b" as the 'format string' input.

Message 2 of 7
(3,112 Views)

Hello Tintin_99,

 

I'd be surprised if there wasn't a function for this in the MGI or OpenG libraries, but as I don't have access to those at the moment to check here's a quick and dirty solution.  It's probably not the most efficient way to do it.

 

Untitled.png

-edit-

As Darren indicated, Scan from String with a Boolean format specifier is the straightforward and easy to interpret later way- specifying a width of 1 and building an array out of the resulting outputs will give you the array of zeroes and ones (this is what I did in that screen capture).

 

Regards,

Tom L.
0 Kudos
Message 3 of 7
(3,103 Views)

tintin_99 wrote:

for example if the string is 1010000 then the it should be converted to 1010000 in (0,1) format. Somthing like Boolean array to (0,1) block


You need to be more specific, because (0,1) is not a format.

0 Kudos
Message 4 of 7
(3,094 Views)

If you know the string is clean (only 0 or 1, no weird characters), you can do the following.

 

 

0 Kudos
Message 5 of 7
(3,086 Views)

This is a rarity, so I have to jump on it.

 

Christian's code can be simplified by subtracting 48 instead of comparing.  Again, this assumes that your string is nothing but ASCII 0 and 1.


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 6 of 7
(3,014 Views)

@crossrulz wrote:

This is a rarity, so I have to jump on it.


Well, let me jump a little higher then. 😄

 

Why do math at all (yes, subtraction is hardcore math!) if all we really need is some cheap bitwise operation??? 😮

 

 

 

 

Message 7 of 7
(2,986 Views)