LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of Decimal to Binary String

Hello Labview People:

I'm rather new to Labview, so this may be a simple-minded question . . .

I would like to take a numeric control and have the decimal input
converted to a binary string of 8 bits. So, for example, if I were to
put in the number '127', I would get out (on an indicator) the string:

01111111

The number '128' would show on the indicator as:

10000000

It seems to me that this should be simple, but somehow I cannot figure
out how to do it. Must an array be built bit by bit to accomplish this?
(I'm afraid I don't yet know how to build arrays.)

Thanks in advance for any help you provide!



Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 1 of 9
(7,234 Views)
Hello Ananda

You can do this by first wiring your digital control to a "Number to
Boolean Array" function (Boolean Palette). This converts the number to an
array of True and False Values. Then wire the output of the "Number to
Boolean Array" function (a green line) to a "Boolean to (0,1)" function,
and this converts the True's to 1, and the False's to 0. Then wire this (a
blue line now) to an "Array to Spreadsheet String" function ("array"
input), with a string constant "%d" (no quotes) wired to the "format
string" input, and an empty string constant wired to the "delimiter"
input. The out put of this function should be the string you want.

If you didn't understand some of this, contact me and I can email it to
you.

Paul Davey



Ananda Dave wrote:

> Hello Labv
iew People:
>
> I'm rather new to Labview, so this may be a simple-minded question . . .
>
> I would like to take a numeric control and have the decimal input
> converted to a binary string of 8 bits. So, for example, if I were to
> put in the number '127', I would get out (on an indicator) the string:
>
> 01111111
>
> The number '128' would show on the indicator as:
>
> 10000000
>
> It seems to me that this should be simple, but somehow I cannot figure
> out how to do it. Must an array be built bit by bit to accomplish this?
> (I'm afraid I don't yet know how to build arrays.)
>
> Thanks in advance for any help you provide!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

--

Research Assistant
School of Physiotherapy, Curtin University of Technology
Selby Street, Shenton Park, Western Australia, Australia. 6008
email: P.C.Davey@curtin.edu.au
Tel. +61 8 9266 4657 Fax. +61 8 9266 3699

"Everyone who calls on the name of the Lord will be saved." Romans 10:12
"For all
have sinned and fall short of the glory of God, and are justified
freely by his grace through the redemption that came by Christ Jesus."
Romans 3:23-4
0 Kudos
Message 2 of 9
(7,234 Views)
Ananda Dave wrote:

> Hello Labview People:
>
> I'm rather new to Labview, so this may be a simple-minded question . . .
>
> I would like to take a numeric control and have the decimal input
> converted to a binary string of 8 bits. So, for example, if I were to
> put in the number '127', I would get out (on an indicator) the string:
>
> 01111111
>
> The number '128' would show on the indicator as:
>
> 10000000
>
> It seems to me that this should be simple, but somehow I cannot figure
> out how to do it. Must an array be built bit by bit to accomplish this?
> (I'm afraid I don't yet know how to build arrays.)

Yes this is poretty simple, but not obvious so don't fret.

Place the control down, right click and select Representation and then U8
Place a "Format into st
ring" on the diagram (from the string palette).
Wire the control to the number input. On the format string input create a
constant
and make it "%08b" (without the quotes). Create a string indicator from the
output.

Now you have an 8 bit binary representation of the number.
If you need more help ask again.
Kevin Kent
0 Kudos
Message 3 of 9
(7,234 Views)
use format into string VI from string palette

format string should be "%08b" for 8 bits, "%016b" for 16 bits etc.

timo

Ananda Dave wrote:
>
> Hello Labview People:
>
> I'm rather new to Labview, so this may be a simple-minded question . . .
>
> I would like to take a numeric control and have the decimal input
> converted to a binary string of 8 bits. So, for example, if I were to
> put in the number '127', I would get out (on an indicator) the string:
>
> 01111111
>
> The number '128' would show on the indicator as:
>
> 10000000
>
> It seems to me that this should be simple, but somehow I cannot figure
> out how to do it. Must an array be built bit by bit to accomplish this?
> (I'm afraid I don't yet know how to build arrays.)
>
> Thanks in advance f
or any help you provide!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
-------------------------------------------------
Timo Miettunen

Fincitec Oy Production Department
e-mail: timo.miettunen@fincitec.fi
Address:
Lumikontie 2 Tel: +358-16-2151245
PO BOX 11 Fax: +358-16-221561
FIN-94600 KEMI Finland
-------------------------------------------------
0 Kudos
Message 4 of 9
(7,234 Views)
Or, you can go under the numeric function, and look for conversions, get
decimal to byte array conversion.

Then what you need to do is to get an array selection vi, and index to zero.

I don't remember the exact name of the VI's because I don't have LabView
here with me.

Perhaps this complicates things 🙂

Steven


"Timo Miettunen" wrote in message
news:39C8784F.7B6E4060@fincitec.fi...
> use format into string VI from string palette
>
> format string should be "%08b" for 8 bits, "%016b" for 16 bits etc.
>
> timo
>
> Ananda Dave wrote:
> >
> > Hello Labview People:
> >
> > I'm rather new to Labview, so this may be a simple-minded question . . .
> >
> > I would like to take a numeric control and have the decimal input
> >
converted to a binary string of 8 bits. So, for example, if I were to
> > put in the number '127', I would get out (on an indicator) the string:
> >
> > 01111111
> >
> > The number '128' would show on the indicator as:
> >
> > 10000000
> >
> > It seems to me that this should be simple, but somehow I cannot figure
> > out how to do it. Must an array be built bit by bit to accomplish this?
> > (I'm afraid I don't yet know how to build arrays.)
> >
> > Thanks in advance for any help you provide!
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> --
> -------------------------------------------------
> Timo Miettunen
>
> Fincitec Oy Production Department
> e-mail: timo.miettunen@fincitec.fi
> Address:
> Lumikontie 2 Tel: +358-16-2151245
> PO BOX 11 Fax: +358-16-221561
> FIN-94600 KEMI Finland
> -------------------------------------------------
0 Kudos
Message 7 of 9
(7,234 Views)
On Wed, 20 Sep 2000 08:38:41 GMT, Timo Miettunen
wrote:

>use format into string VI from string palette
>
>format string should be "%08b" for 8 bits, "%016b" for 16 bits etc.
>
>timo
>
>Ananda Dave wrote:
>>
>> Hello Labview People:
>>
>> I'm rather new to Labview, so this may be a simple-minded question . . .
>>
>> I would like to take a numeric control and have the decimal input
>> converted to a binary string of 8 bits. So, for example, if I were to
>> put in the number '127', I would get out (on an indicator) the string:
>>
>> 01111111
>>
>> The number '128' would show on the indicator as:
>>
>> 10000000

And if you have a 32 bit number and want a space beetween each 8 bit
byte then use the split number function (
from the
Advanced->Data Manipulation function palette). Split the 32 bit number
until you get 4 eight bit numbers and use the Format into string
function.

Wow, why didn't i think of this before. I have to rewrite some code
now, thanks for the idea about using Format into string.
--
Rolf
0 Kudos
Message 8 of 9
(7,234 Views)
Hi,

It is easy to do with one VI "format into string" you connect the numeric
input to the left bottom corner, and
connect only the format string and have it be<%b> , the output string will
show what you wanted,


ilan,

"Ananda Dave" wrote in message
news:8q8ss1$rc8$1@nnrp1.deja.com...
> Hello Labview People:
>
> I'm rather new to Labview, so this may be a simple-minded question . . .
>
> I would like to take a numeric control and have the decimal input
> converted to a binary string of 8 bits. So, for example, if I were to
> put in the number '127', I would get out (on an indicator) the string:
>
> 01111111
>
> The number '128' would show on the indicator as:
>
> 10000000
>
> It seems to me that this should be simple, but somehow I cannot figure
> ou
t how to do it. Must an array be built bit by bit to accomplish this?
> (I'm afraid I don't yet know how to build arrays.)
>
> Thanks in advance for any help you provide!
>
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Kudos
Message 5 of 9
(7,234 Views)
On Tue, 19 Sep 2000 23:29:27 GMT, Ananda Dave
wrote:

>Hello Labview People:
>
>I'm rather new to Labview, so this may be a simple-minded question . . .
>
>I would like to take a numeric control and have the decimal input
>converted to a binary string of 8 bits. So, for example, if I were to
>put in the number '127', I would get out (on an indicator) the string:
>
>01111111
>
>The number '128' would show on the indicator as:
>
>10000000
>

The simplest way would be to
Step 1 : Set the representation of the number
to an integer or unsigned
(Right click on indicator and select representation)
Step 2 : Set the format and precision to show binary
(Right click on indicator and select
Format & Precision)

On
e drawback with this is that you loose leading zeroes.
--
Rolf
0 Kudos
Message 6 of 9
(7,234 Views)

I kinda have the same problem. I want to convert SEQRECORD429 OUT to output in a 32 bit word anb then to a binary ouput. Then assign each each bit as needed. I have attached my vi snipid. Hopefully I am doing this posting right. New to labview and Ni Forums

 

Thank you

0 Kudos
Message 9 of 9
(5,194 Views)