LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Numbers bigger then 10 to a array of integers

Solved!
Go to solution

Okay I want to do the following...

 

I have a number (bigger then 10). Assume I got the number 4327 now I want to change this number to a numeric array with the values [4,3,2,7] as fast as possible.

 

I only thought of one solutions (which is possible also the fastest), but I want to know if anyone has maybe a better idea.

 

My solution is just to cast that number to a string using the NumberToString VI, "4327", then split into a array of strings ["4","3","2","7"], and cast it back using the StringToNumber VI.

 

Anyone got a better faster idea?

0 Kudos
Message 1 of 25
(3,591 Views)

If the range of input is not too huge the fastest way might be to precreate an array and index it

=====================
LabVIEW 2012


0 Kudos
Message 2 of 25
(3,590 Views)

Login.PNG

Let the UI thread help you?  (works for any base!)


"Should be" isn't "Is" -Jay
Message 3 of 25
(3,583 Views)

Why convert to strings and back?  Just use a bit of math:

individual digits.png

Message 4 of 25
(3,576 Views)
But are those two methods the "fastest" ways?
=====================
LabVIEW 2012


0 Kudos
Message 5 of 25
(3,573 Views)

This is faster than the previous two.

 

get digits.png

Message 6 of 25
(3,564 Views)

@matt W wrote:

This is faster than the previous two.


On my machine, at least, my approach is about 20ms faster (for 1 million 7-digit numbers).  Attached is the VI I used for benchmarking.

 

0 Kudos
Message 7 of 25
(3,550 Views)
Solution
Accepted by topic author WG-

Absolutely not!

 

Although Nathand's solution could be expanded to work with any base as well. This may be a bit faster

untitled2.PNG

the use of native recursion vs the buffer expansion should show in favor of the recusive technique up to a considerable number of digits.


"Should be" isn't "Is" -Jay
Message 8 of 25
(3,548 Views)

@Jeff Bohrer wrote:

Absolutely not!

 

Although Nathand's solution could be expanded to work with any base as well. This may be a bit faster

 

the use of native recursion vs the buffer expansion should show in favor of the recusive technique up to a considerable number of digits.


Nowhere close, unfortunately.  Here's the benchmarking VI updated with your code, which is 4-5x slower than both my approach and Matt W's.  The recursive implementation is a good idea but LabVIEW's recursion is not terribly efficient.  Each recursive copy requires allocating an entirely new copy of the VI.

 

EDIT: uploaded recursive subVI, needed as well.

Download All
Message 9 of 25
(3,543 Views)

@matt W wrote:

This is faster than the previous two.

 

get digits.png


I'd go with that, it is fast enough. 😄

 

However, make sure that the input is never negative. 😄

Message 10 of 25
(3,539 Views)