LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

add leading 0's to binary number

Solved!
Go to solution

One feature that you can make use of is "Auto Indexing" of arrays in loops.  See the attached image of your code with the auto indexing being used.

 

Message Edited by paulmw on 04-04-2009 03:16 PM
Message 11 of 19
(2,450 Views)

Attached is an image of code that should produce the same final integer array of 0's and 1's that your latest version generated.  Altenbach suggested, "All you need is blue wires".  I found that difficult with your integer to bit stream conversion requiring only 26 bits. There is probably something I am not considering.   But, what I propose should be more efficient than converting to ASCII strings of 0's and 1's then back again.  It uses boolean arrays.

 

P.S. you can remove the reverse array to perform the last request in your code.

 

Message Edited by paulmw on 04-04-2009 03:27 PM
Message 12 of 19
(2,446 Views)

krispiekream wrote:

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.


First, the real bug in your code is the fact that you initialize the full size array in the second loop, but then use "insert into array" to add your data. this casues the final array to be twice as big as it should be. The correct operation would be to use "replace array subset". Anyway, as I already said, autoindexing is better (see also paulwm's solution above).

 

Pauls's second solution is somewhat inefficient. Growing arrays in loops is expensive because of the need for constant memory reallocations. Here's an alternative that works on the big output array "in place". See if you can get it to work. 😉

 

(to get your old result, you would remove the "reverse array". Test and see what you need)

 

Message Edited by altenbach on 04-04-2009 05:34 PM
Message 13 of 19
(2,429 Views)

@altenbach wrote:


 

Wouldn't it be better to replace that interior for loop with just a subtraction and subtract 48 from the array (the array values will be either 48 (0) or 49 (1))?

Message 14 of 19
(2,410 Views)

this is a really dumb question..

but i have thought of the string bytes array function...

but i got the value of 48 or 49 and i didnt know want it was so i didnt use it..

can someone please explain? 

Best regards,
Krispiekream
0 Kudos
Message 15 of 19
(2,406 Views)

Matthew Kelton wrote:
Wouldn't it be better to replace that interior for loop with just a subtraction and subtract 48 from the array (the array values will be either 48 (0) or 49 (1))?

 

 

Yup, that would be a bit cleaner (see picture). 🙂 

 

 

 

krispie:48 and 49 are the of the letters 0 and 1, respectively. thus a 0 will give the 48, for example. Try it! 🙂

Message Edited by altenbach on 04-05-2009 12:33 AM
Message 16 of 19
(2,398 Views)
Message 17 of 19
(2,390 Views)

altenbach wrote:

Pauls's second solution is somewhat inefficient. Growing arrays in loops is expensive because of the need for constant memory reallocations. Here's an alternative that works on the big output array "in place". See if you can get it to work. 😉


I had a feeling I would get called on that one 🙂

 

So, I offer up my solutions with the pre-allocated array-

 

Message Edited by paulmw on 04-05-2009 02:30 PM
Message 18 of 19
(2,369 Views)

krispiekream wrote:

this is a really dumb question..

but i have thought of the string bytes array function...

but i got the value of 48 or 49 and i didn't know want it was so i didn't use it..

can someone please explain? 


After the conversion of the of the integer to a "binary" string (with the padded zeros) the actual string is in ASCII form displaying ASCII 1's and 0's.  The numerical value that the computer stores for an ASCII character is 8 bits in size and is used to translate all alphanumeric (and other) characters with in this 8 bit size.  What you see as 0's and 1's in the indicator are actually stored as a decimal 48 and 49 (or in hex 0x30 and 0x31).  That is probably why Altenbach questioned you early on about:

  • What is your definition of "binary numbers"? A binary formatted string perhaps? Maybe a numeric?
  •  

    I hope I explained it sufficiently.

    Message 19 of 19
    (2,365 Views)