LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a binary string to a number...

Hi guys,
I'm trying to convert a binary string into a decimal integer. I'm not sure if LabVIEW has a VI that does that. I haven't found one yet. Basically, say I have the string '0101'. I want to convert that to the value '5'. Or say I'm using hex, I want '10101111' to be converted to 'AF'. So that's my dilemma. I'm hoping I'm not going to have to make my own VI. Thanks a lot!

-Mike
0 Kudos
Message 1 of 4
(11,839 Views)
LabVIEW has exactly what you want even if it can be hard to find it.

To convert a binary text string like "0101" to a decimal value can easily be done using the Scan Value function found under the String/Number conversion section. If you provide the format %b to it (not mentioned in the manual) you will get the decimal value of your binary string.

Also, on your front panel you can change the format of your numerical indicators by right clicking on it and selecting Format & Precision. If you have a numerical indicator you can set it do display the numbers in e.g. hexadecimal form.

However, if you want to convert a number to a hexadecimal text string you can use the Number to Hexadecimal String function also found under the String/Number conversion section.

I
attached a simple example, Conversions.vi, that shows how it works. I hope this helps. /Mikael
Message 2 of 4
(11,839 Views)
Wow Mikael,
Thanks for the great answer and the sample VI. Just what I needed. Thanks for the help.

-Mike
0 Kudos
Message 3 of 4
(11,839 Views)
The function you want is String/Scan From String. Change the format
string to %b to scan a binary string. This will output an I32 value.
Then use String/Format Into String to directly convert to any other
string format that you want.

- Michael

Bonhomme wrote in message news:<5065000000080000009D240000-993342863000@exchange.ni.com>...
> Hi guys,
> I'm trying to convert a binary string into a decimal integer. I'm
> not sure if LabVIEW has a VI that does that. I haven't found one yet.
> Basically, say I have the string '0101'. I want to convert that to the
> value '5'. Or say I'm using hex, I want '10101111' to be converted to
> 'AF'. So that's my dilemma. I'm hoping I'm not going to have to make
> my own VI. Thanks a l
ot!
>
> -Mike
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 4 of 4
(11,839 Views)