Jump to content
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

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