LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Text to Binary to text

Hi there,

I was wondering how I can convert back from binary to text. I'm using this program to text components for a large scale project, and it successfully converts from text to binary. However the second part of the VI, which converts from binary to text, doesn't work. Any ideas? 

 

 

0 Kudos
Message 1 of 6
(2,262 Views)

Yep.  You did it wrong.  Suppose your input string is 12345, 5 characters, 5 bytes.  You change it to a 1D array of U8 (Array of 5 U8s), convert to concatenated array of Booleans (40 bits), then repeated (10 times!) take the 40 bit number and turns it into a 32-bit Integer (over-and-over again), then (10 times) interprets the low 8 bits into a byte (which happens to be 1 in this case, giving 1111111111).

 

There are several "fixes".  Try to find them yourself -- it will be good practice and a learning experience.

 

Bob Schor

0 Kudos
Message 2 of 6
(2,233 Views)

Bob isn't trying to be mean; he's trying to make you a better programmer.  You don't learn anything by asking someone to fix things for you all the time.  This should be simple enough to fix if you just poke around a bit.  If you cannot find the solution by yourself, by all means post what you have and describe what you've tried.  We'll be happy to guide you towards enlightenment.  🙂

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

To better understand what your original code is doing, open its Block Diagram, and click on the fifth icon (look like a Light Bulb, is called "Highlight Execution") on the Menu Bar.  Now run your code.  You will actually "see" the code execute in Slow Motion, and can see some of the values (or sizes, for Arrays) in the Wires.  Try my example, the string "12345", and recognize that the Ascii code for "1" is 49, with "5" being 53.  The first two functions and the last two functions are "inverses", so should "undo" what was done "in between" -- it's the "in between" that you go astray.  Watch what happens there ...

 

Bob Schor

0 Kudos
Message 4 of 6
(2,215 Views)

Thanks for your responses guys. I got it all working and implemented it into my final system. I understand it's better to learn, and learn I have. Much appreciated, everyone. In case you're curious, I've attached the final VI with the conversion implementation.

0 Kudos
Message 5 of 6
(2,210 Views)

Good for you!  Here is the solution I came up with, and in the process, learned something I didn't know about the Boolean Array to Number function.  Did you notice the red "Coercion dot" at the input to the function in your code?  This means that the input Wire (which looks like an Integer Array) is the wrong Type, i.e. not a U8.  It is, in fact, a U32.  Why, and why is there no Coercion dot in my code (shown below)?  Well, if you look at the Help for Boolean Array to Function, you find that you can specify the format of the Integer Output it produces, so I chose the U8 output (as I knew I was dealing with a Boolean Array that originated as a U8, so it would be 8 bits wide).  Here's my code, but yours works, as well ...

String to Bool to StringString to Bool to String

Bob Schor 

0 Kudos
Message 6 of 6
(2,203 Views)