07-01-2016 08:03 AM - edited 07-01-2016 08:12 AM
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.
Solved! Go to Solution.
07-01-2016 08:08 AM
07-01-2016 08:31 AM
@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
07-01-2016 08:34 AM - edited 07-01-2016 08:35 AM
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! 😄
07-01-2016 08:46 AM
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.
07-01-2016 09:01 AM - edited 07-01-2016 09:02 AM
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 !
07-01-2016 09:08 AM
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
07-01-2016 09:20 AM
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
07-01-2016 09:36 AM
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.
07-01-2016 09:51 AM
Set the minimum value for the control properties to be 0 and the maaximum value to be 99999