Jump to content
News about the LabVIEW Wiki! Read more... ×
Sign in to follow this  
Wouter

IsOdd

Recommended Posts

VI Name:

IsOdd

Total VIs:

7

Description:

Checks if a number is odd (true) or even (false)

Note:

-

Blockdiagram:

gallery_17774_56_5856.png

Code:

Numeric IsOdd.zip

What are you thoughts on this VI?

  • Would you like to see such a function in OpenG?
  • Can you optimize the code?
  • In which package should it be included?
  • Should it be rejected?

Share this post


Link to post
Share on other sites

This might be a usefull function. Another implementation is 'Request and remainder' with 2, and typecast the remainder output to boolean. (that would be an 'is even?' output.

Ton

Share this post


Link to post
Share on other sites

Instead of ShiftRight I guess you mean 'Rotate with carry':

bs65o.png

And since there is essentially such a node, we don't need a new OpenG function.

Wouter, thanks for the idea. Ryan thanks for the little used function.

Ton

Share this post


Link to post
Share on other sites

Yes, that's the node I ment. Working with LabVIEW FPGA I make use of that function all the time. The same node is also useful for divide by 2, along with the shift left with carry for multiply by 2 .

  • Like 1

Share this post


Link to post
Share on other sites

Hmmm knew about the node but did not think of using it like that. But I'm sure that my version is faster. The rotation is O(n) while my function is O(1), proberbly it will not make that big difference but still. Further I like mine more because it is just 1 line, in a manner of speaking that the wire changes position :P (moves up)

Share this post


Link to post
Share on other sites

Actually, the Shift Right with Carry is O(1); since all processors (to the best of knowledge) have a shift instruction making it a single instruction (perhaps 2, if you include the register check), rather then the 3 from you version. As for a memory efficiency, I'm pretty sure that no data copy is made since the shifted value is not used. Feel free to benchmark it, I found that the Shift Right with Carry had a 2x improvement using a 64bit Integer. Though unless your doing millions of Is Odd evaluations the calculation time is insignificant. I just don't see a reason to have an OpenG function for this operation, since the Shift Right with Carry in already available.

I included the VI I used for the benchmark.

Is Odd.vi

Edited by Ryan Podsim
  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.