LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

separate integer digits to array

Greetings all

Can someone tell me how do i separate integer in to separate digits in an array.

Eg: 4409

array elements: 44

                            9

 

Thanks and Regards

Baig

0 Kudos
Message 1 of 9
(2,946 Views)

Aren't these four digits: 4 4 0 9 ?

0 Kudos
Message 2 of 9
(2,914 Views)

Hi

it is but since those are integers 09 will be 9

Thanks and regards

Baig

0 Kudos
Message 3 of 9
(2,903 Views)

So you don't' want to separate digits.  You want to separate PAIRS of digits?

0 Kudos
Message 4 of 9
(2,872 Views)

This is how I would do it. If you change the 2 to a different number it would give how ever many digits.

 

Seperate Numbers.png

Tim
GHSP
0 Kudos
Message 5 of 9
(2,866 Views)

I would use Quotient and Remainder and divide by 100.

Message 6 of 9
(2,847 Views)

You are still not giving us sufficient information.

 

  • Is the input a string with four character or a numeric?
  • If it is a numeric, what is the datatype?
  • Are negative inputs allowed, and if so, how should they be handled?
  • Is it always four digits or can it be variable length?
  • What should be the output datatype?

Typically it is much easier to solve a problem if you would attach a very simple VI that contains the actual data and desired output.

 

Here's a slightly more scalable version of the above that can deal with any number of digits supported and will output all decimal digit pairs of the positive input integer.

 

altenbach_0-1574269357998.png

Message 7 of 9
(2,829 Views)

All of the previous methods have been a simple way to accomplish this problem, so I decided to make a hard way to accomplish this problem. I also assumed that the task is to get each single digit, not pairs of digits; if you want pairs of digits, that is left as an exercise to the reader.

 

challengemode.png

0 Kudos
Message 8 of 9
(2,809 Views)

I like Bert's solution, but the latent Mathematician in me calls out for a Recursive solution (which, of course, is very simple to write in LabVIEW).  I made the input a U32, thereby getting rid of a possible ambiguity if you put in a negative integer.  I also assumed that the number 4409 (using our usual "digit-place representation" of numbers, has the digits "4", "4", "0", and "9".  Here is the (almost trivial) VI, showing the Recursive call -- this version puts the digits of 4409 in an Array starting with the Least Significant Digit (i.e. "9") -- reversing the order of building the Array will give the digits in the reverse order.  Enjoy!

U32 to DigitsU32 to Digits

 Bob Schor

 

Message 9 of 9
(2,784 Views)