LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Quotient & remainder

Hi all,

I am currently using Quotient & Remainder (under Numeric) to convert decimal value to binary. However, when I try to retrieve the quotient for 2/2, instead of giving a value 1, it gives floor(x/y) = floor(2/2) = 0. Why is that so? How can i make it such that when 2/2, i would get the quotient of 1?

Any help is greatly appreciated.

Thank you...
0 Kudos
Message 1 of 8
(6,068 Views)
It works just fine here. What number type do you connect? Remember that floating point number might have subtle differences, way beyond the decimal point. e.g. you might actually calculate 1.99999999999/2.000000000001. Are your inputs obtained as a result of some calculation. Place some indicators on your input and display them with 20 decimal digits.

Create a diagram constant with the number 2 and wire it to both inputs--> now it's guaranteed to be the same.
0 Kudos
Message 2 of 8
(6,063 Views)

@aiya wrote:
Hi all,

I am currently using Quotient & Remainder (under Numeric) to convert decimal value to binary. However, when I try to retrieve the quotient for 2/2, instead of giving a value 1, it gives floor(x/y) = floor(2/2) = 0. Why is that so? How can i make it such that when 2/2, i would get the quotient of 1?

Any help is greatly appreciated.

Thank you...



There is nothing wrong with the Q&R function, and 2/2 is indeed equal to one. However, something is puzzling me here : you said that you want to convert a decimal value to binary ? I'm not sure that this is the proper path, and your problem is probably here. Post a vi illustrating your problem or develop a bit more your question to get more help.

CC

Message Edited by chilly charly on 04-20-2005 04:38 AM

Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 3 of 8
(6,065 Views)
Hi all,

I have attached the .VI, try putting in a value of 3162, the conversion to binary is incorrect.
Any kind help is greatly appreciated.
0 Kudos
Message 4 of 8
(6,045 Views)
There is a very high chance that these successive divisions will cause rounding errors.

Your approach seem overly complicated but will probably work if you convert your numbers to integers before the loop. However, try the alternative solution also shown in the attached VI, it's much simpler. 🙂

If this is just for display, there is no reason to make an array output. Simply make a binary indicator as shown on top in the diagram.

Message Edited by altenbach on 04-20-2005 09:26 AM

Message 5 of 8
(6,041 Views)
Hi Altenbach,

Thanks for your brilliant solution! It works well... I can convert any numbers that I want. Just curious, what does it mean for unsigned 16-bit integer & the MSB & LSB as the type of unsigned byte?
0 Kudos
Message 6 of 8
(6,012 Views)
There is no relation between the data representation of your MSB and LSB arrays and your original data. Each array elements represents one bit, so only the array lenght should match the number of bits in your original number.
Any numeric representation (U8, I32, DBL, EXT, etc.) can easily represent zeroes and ones, so any of them will do just fine, but some are more economic than others. 😉

In this particular case, they appear as U16 because this is the default output for "Boolean to (0,1)" for some unknown reason. You can convert it to anything you like.

Message Edited by altenbach on 04-20-2005 06:26 PM

Message 7 of 8
(6,005 Views)
Hi altenbach,

I have a better understanding now. Thank you for your help!!! 🙂
0 Kudos
Message 8 of 8
(5,971 Views)