LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Flip digits

Solved!
Go to solution

How to reverse the number using labview with given number and number of digits? Just want numerical operation only.  For example 56789 will become 98765. tq.

0 Kudos
Message 1 of 31
(5,913 Views)

Hi Ambrose,

 

convert the number to a string, then reverse the string…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 31
(5,906 Views)

@Ambrose1464 wrote:

How to reverse the number using labview with given number and number of digits? Just want numerical operation only.  For example 56789 will become 98765. tq.


That qualifier is interesting.

 

As Gerd posted, converting to string makes this question trivial, but to do it numerically complicaites the game quite a bit.

 

Is Gerd's solution good for you?

 

If not can you share the reson you want a stictly numeric approach?

 

Curious,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 31
(5,896 Views)

Hi,

 

As Gerd posted, converting to string makes this question trivial, but to do it numerically complicaites the game quite a bit.

To make it "all numerical" you can

1. create an array of single digits using Quotient&Remainder in a loop.

2. reverse the array

3. create a number from the array by calculation the sum of array[i]*10^i

 

Sounds quite simple…

 

When you see the string as an array of bytes it can be counted as "numerical" too! 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 31
(5,894 Views)

I first time learner using labview. will you show me how does the block diagram look like? i have no idea how does the connection is connect.

0 Kudos
Message 5 of 31
(5,889 Views)

Hi Ambrose,

 

I guess this is homework. And I think it is a very nice way to learn LabVIEW!

 

Usually you present your VI and ask specific questions on problems you have - then we will respond. But asking for someone else solving your homework isn't "nice"…

 

Some pseudocode:

x := FLOOR(ABS(x))
REPEAT array[i] := x modulo 10 x := x \ 10 (* integer division *) UNTIL x = 0 ReverseArray(array) y := 0 FOR n = each element in array y := array[n] * 10^n + y NEXT

When learning LabVIEW you should take the lessons on array handling and autoindexing in loops…

 

To learn LabVIEW you should start at www.learnni.com !

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 31
(5,879 Views)
Solution
Accepted by topic author Ambrose1464

Hi Ambrose

The simple Method is follow as Suggested by Gerd

If u want only in Numeric Operation then you can follow the attached Snippet

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 31
(5,876 Views)

This question gets at a number of basic programming questions and methodologies common in (most) computer languages, including LabVIEW.

 

Let's start by asking what basic steps you need to take to reverse the digits of a number.  Well, you need to know how to break a number up into digits.  A simpler question is, giving an N-digit number, give me two numbers, one composed of the first N-1 digits, and the second being the least significant (right-most) digit.  [As an added "bonus", make this work for Hexadecimal numbers (base 16), decimal numbers (base 10), and binary numbers (base 2) -- it is really exactly the same problem, but some details may change].

 

Can you see how to do this?  Do you understand what numerical operation you need to perform on 12345 to return 1234 and 5?

 

Once you have figure out this basic step, you now need to develop an algorithm, a series of (simple) steps that you do, often over-and-over, until you arrive at the answer.

 

One way to reverse a multi-digit number iteratively is to first loop, carving off (and saving) the least-significant digit one at a time until there are no more digits left.  Now we have all of the digits, so we reassemble them (ah, yes, you have to know how to take "1234" and "5" and combine them arithmetically to get "12345") in the reverse order.  If the numbers are in an array, we could use the Array Function "Reverse 1D Array" to help us out.

 

I've deliberately not specified any LabVIEW code here, as you are supposed to be learning LabVIEW, so will want to familiarize yourself with its Numeric functions, its Array functions, and how its looping structures (particularly the For Loop) interact with Arrays.

 

Good Luck.

 

Bob Schor

0 Kudos
Message 8 of 31
(5,865 Views)

thank you for you all help me . 1 more additional , how to control the number of digits used? for example when i key in number of digit is 5 then maximum i can key in the numeric constant is 34567 and cannot more than 5 digit number. I know C programming, but i still dunno how to implement on Labview.

0 Kudos
Message 9 of 31
(5,856 Views)

Set the minimum value for the control properties to be 0 and the maaximum value to be 99999

0 Kudos
Message 10 of 31
(5,845 Views)