Wouter Posted September 3, 2011 Report Share Posted September 3, 2011 VI Name: IsOdd Total VIs: 7 Description: Checks if a number is odd (true) or even (false) Note: - Blockdiagram: 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? Quote Link to comment
Ton Plomp Posted September 4, 2011 Report Share Posted September 4, 2011 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 Quote Link to comment
Ryan Podsim Posted September 4, 2011 Report Share Posted September 4, 2011 How about use a shift right? The output is then "Is Odd?" 1 Quote Link to comment
Ton Plomp Posted September 4, 2011 Report Share Posted September 4, 2011 Instead of ShiftRight I guess you mean 'Rotate with carry': 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 Quote Link to comment
Ryan Podsim Posted September 5, 2011 Report Share Posted September 5, 2011 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 . 1 Quote Link to comment
Wouter Posted September 6, 2011 Author Report Share Posted September 6, 2011 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 (moves up) Quote Link to comment
Ryan Podsim Posted September 6, 2011 Report Share Posted September 6, 2011 (edited) 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 September 6, 2011 by Ryan Podsim 2 Quote Link to comment
Wouter Posted September 7, 2011 Author Report Share Posted September 7, 2011 Ya correct I forgot that first part. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.