LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

add leading 0's to binary number

Solved!
Go to solution

hi,

i am learing labview and i wanted to do something like this..

i want to read in a text file.

convert the decimal numbers to binary numbers

and then add leading zeros if the lenght of the binary is less than X number.

and then ultimately sum up all binary numbers and parse it into 1 bits as 1 array.

the reason for me doing this because i am generating a singal.

i have started on this, but i am stuck at the comments, can someone help me out. 

thank you in advance..

 

Message Edited by Giangliang on 04-02-2009 06:54 PM
Download All
0 Kudos
Message 1 of 19
(9,379 Views)
Solution
Accepted by topic author Giangliang

The Format Into String Function will do this for you.  Right click and change the options to pad with zeros.

 

Message Edited by paulmw on 04-02-2009 09:18 PM
Download All
Message 2 of 19
(9,363 Views)

I am having problems with your terminology, especially since the VI you have attached seems t do something else.

 

  • You are not summing up the numbers, but the sizes. What do you want to sum up? Do you want to count 1s?
  • What is your definition of "binary numbers"? A binary formatted string perhaps? Maybe a numeric?
  • Can you tell us the connection between binary formatted strings and "signals"?

 

Message 3 of 19
(9,330 Views)

paulmw, thank you..that advice works like a charm.

hmm...my vi shows the summing up of the string lenght because I wanted to verify that i get about 1690 bits for 64*26 bits and about 64*27=1728 bits.

that help me verify that the signal i am generating from the text file is equal to the signal from ni-6534 card.

binary numbers to me are numbers of 1s and 0s, 01010101, etc.

binary numbers in string let me count the numbers of bits? or is there an easier way?

with that in mind, i want to sum up all the resulting string into 1 big array of 1728 bits...then parse each bit up...

 lets say i have 10101

i want to make it

array1=1,0,1,0,1?

 

0 Kudos
Message 4 of 19
(9,314 Views)

i think i am doing it right?

my concept of generating a signal from a text file?

i am still missing one thing...

parsing out bit by bit into an array of 1728bits...

0 Kudos
Message 5 of 19
(9,307 Views)
i got it to here, but i am facing some bug.

 

Message Edited by Giangliang on 04-03-2009 10:26 AM
0 Kudos
Message 6 of 19
(9,303 Views)

OKAY..I GOT IT..THANK YOU GUYS FOR ALL YOUR HELP...

I REALLY APPRECIATED!!!

0 Kudos
Message 7 of 19
(9,286 Views)

Can you show us your final version? Your v6 is sitll an absolute mess. 😉

 

Most of your code is very inadequate and overly complicated. None of your shift registers make any sense, you can delete the (1) shift registers, (2) index array, (3) insert into array (4) initialize array, etc. and replace all with two simple autoindexing tunnels.

 

I still don't quite understand what you need, but my best guess is that it can be done with code the size of a postage stamp.

 

To count the number of "1" bits in an array of numeric intergers, you can use e.g. a 16 bit lookup table, no strings or formatting operations needed. It will be many orders of magnitude faster and simpler. All you need is blue wires.

 

Please show us the final version that gives the correct and desired result so we can show you how to do this right. 🙂

0 Kudos
Message 8 of 19
(9,280 Views)

altenbach wrote:

Please show us the final version that gives the correct and desired result so we can show you how to do this right. 🙂


I agree.  Great to hear that you got it working but I kind of expected to see more follow up questions addressing the same things that Altenbach already pointed out.  Lets see what you got!

Message 9 of 19
(9,257 Views)

i would love to...

that's why i am here. 

i want to learn labview the easy way.

i really think the code could be done in an easier way.

i like to use alot of indicators on my block diagram because i like the see results of all manupilations, but besides that..i think that its too complicated as well.

i have a comment on the block diagram. 

i need to reverse the order of the binarys before padding the leading 0s.

 

 

Best regards,
Krispiekream
0 Kudos
Message 10 of 19
(9,217 Views)