LabVIEW

cancel
Showing results 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

Message 1 of 9
(2,954 Views)

Re: separate integer digits to array

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

Message 2 of 9
(2,922 Views)

Re: separate integer digits to array

Hi

it is but since those are integers 09 will be 9

Thanks and regards

Baig

Message 3 of 9
(2,911 Views)

Re: separate integer digits to array

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

Message 4 of 9
(2,880 Views)

Re: separate integer digits to array

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

Tim
GHSP
Message 5 of 9
(2,874 Views)

Re: separate integer digits to array

I would use Quotient and Remainder and divide by 100.

Message 6 of 9
(2,855 Views)

Re: separate integer digits to array

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.

Message 7 of 9
(2,837 Views)

Re: separate integer digits to array

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.

Message 8 of 9
(2,817 Views)

Re: separate integer digits to array

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 Digits

Bob Schor

Message 9 of 9
(2,792 Views)