LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why did blue wires turn orange when changing from subtract to divide operation?

Solved!
Go to solution

Hello all,

I"m wondering what happened in my block diagram.

 

I had a section that had a subtraction operation with numbers.....I realized I needed to divide by 2 rather than subtract by two (been a long few days here)...and when I did this, all the wires turned orange from the blue before...

 

I have a compound arithmetic adding 3 numeric values coming in...going through a case statement....case 0 default passes the values through, case 1 divides by two...

 

Is there a datatype change here I don't understand?

 

Thank you in advance,

 

cayenne

0 Kudos
Message 1 of 11
(5,583 Views)
Solution
Accepted by topic author cayenne

Dividing an odd integer value leaves you with a decimal number. Labview therefore decides it is best for you to use a floating point representation (double in this case) so no data is lost.

 

There are several alternatives if you don't want your data type to change: quotient & remainder function, scale by power of 2 function (in this one you'll have to think of a way to distinguish odd from even numbers if you need it to)

 

You can, of course, also change the data type back to integer after the division.

LabVIEW 2012 32 bit

I am not an expert!
Message 2 of 11
(5,581 Views)

As has been mentioned, a division of two integers is typically not an integer and LabVIEW will generate an floating point output for that reason. You can right-click the division and look at the output configuration options and you will notice that you cannot even select integer representation. The output would be too unpredictable.

 

Factors of two are very "special" in a binary system. In addition to the mentioned "Qotient&Remainder" and "scale by power of two", you can also use a simple logical shift (y= -1 for a division by two) to divide by two. Of course if the input is odd, you'll truncate the result.

Message 3 of 11
(5,567 Views)

@altenbach wrote:

As has been mentioned, a division of two integers is typically not an integer and LabVIEW will generate an floating point output for that reason. You can right-click the division and look at the output configuration options and you will notice that you cannot even select integer representation. The output would be too unpredictable.

 

Factors of two are very "special" in a binary system. In addition to the mentioned "Qotient&Remainder" and "scale by power of two", you can also use a simple logical shift (y= -1 for a division by two) to divide by two. Of course if the input is odd, you'll truncate the result.


Christian, I use LV2009,and I don't see any output configuration for division is that added in later version? (Maybe I'll check later)

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 11
(5,561 Views)

Oh yes I got it its in the properties. Thanks for the explanation

-----

The best solution is the one you find it by yourself
0 Kudos
Message 5 of 11
(5,558 Views)

Yes, output configuration is a relatively recent addition to LabVIEW. Do you see it for other functions?

 

Here's the 2012 panel:

 

Message 6 of 11
(5,557 Views)

@altenbach wrote:

Yes, output configuration is a relatively recent addition to LabVIEW. Do you see it for other functions?

 

Here's the 2012 panel:

 


Yep, I see this...and the U32 that I'm doing everything in, isn't an option.

 

How can I change this output to be U32 so everything will be the same when compared later in my vi?  I won't have any reminders when the code is running correctly....this is to take care of a case were I do some thing in pairs rather than singlets....

 

Thanks,

 

cayenne

0 Kudos
Message 7 of 11
(5,546 Views)

@cayenne wrote:

@altenbach wrote:

How can I change this output to be U32 so everything will be the same when compared later in my vi?  I won't have any reminders when the code is running correctly....this is to take care of a case were I do some thing in pairs rather than singlets....


We already gave you the answer!!!

 

"logical shift" or "scale by power of two". If the upper input is -1, the lower input will be divided by 2, keeping the U32 representation.

 

(note that the two operations are not equivalent for signed integers and negative lower inputs.)

 

 

Message 8 of 11
(5,543 Views)

@altenbach wrote:

@cayenne wrote:

@altenbach wrote:

How can I change this output to be U32 so everything will be the same when compared later in my vi?  I won't have any reminders when the code is running correctly....this is to take care of a case were I do some thing in pairs rather than singlets....


We already gave you the answer!!!

 

"logical shift" or "scale by power of two". If the upper input is -1, the lower input will be divided by 2, keeping the U32 representation.

 

(note that the two operations are not equivalent for signed integers and negative lower inputs.)

 

 

 

 


Sorry....I'm not familiar with  "logical shift" or "powers of two" function. I was trying to research this...then read the thread again, and missed the part about the Quotent/Remainded operation...I used that and just taking the quotient part out and that got me back to my data type.

 

I'll look up the logical shirt and powers of two functions....those are new concepts to me....

 

But for now, the quotient and remainder is working for me.  I'm only dividing integers, and it will come out even (if not, I've got more problems than this)  🙂

 

Thank you for the assistance and introduction of new ideas and concepts...!!!

 

cayenne

0 Kudos
Message 9 of 11
(5,526 Views)

Well, the other two are certainly more efficient and logical.

 

The Q&R operation is more complicated and actually produces two outputs, while you actually only use one of them. Scale by power of two is definitely a better option when dealing with powers of two.

0 Kudos
Message 10 of 11
(5,511 Views)