The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

CLAD2017 - Answer the Requirement - Even Stevens

Active Participant

You are tasked to write a VI?

INPUT(s): Numeric an U32 Numerical Value.

OUTPUT(s): Value is Even a Boolean Value.

FUNCTION:  The VI must return TRUE if Numeric is an Even Number.

 

Have a go at coding the VI yourself or expand the Spoiler Tag to see the possible answers.

 

Spoiler
a)
IsEven1.png

b)
IsEven2.png

c)
IsEven3.png
d)
IsEven4.png

Combined.png

Comments
Member

a,b & D

Member

A,B, & D

Happy to Wire
Knight of NI

A, B, D

 

From benchmarks I have seen for finding an odd value, B would be the most efficient.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Member

I wrote B.  I forgot about the equal to zero block, so I checked the remainder against zero with a constant, but I basically wrote B.

What are the advantages to A or D?  They seem less efficient.

Seth Price, N3MRA
Lab Associate, Chemical Engineering Department - New Mexico Tech
Lab Assistant, Sodium Dynamo Project
Knight of NI

What are the advantages to A or D?  They seem less efficient.


A is the most direct method based on the definition of an even number (divisible by 2).  It is therefore much easier for people to understand.

D has no advantage other than it will produce the right answer.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Active Participant

For checking for an odd number, the most efficient is probably Rotate Right With Carry - the Least Significant Bit is returned directly.  Of course IsEven is easily computed from this too.  RRWC also has a benefit on an FPGA as it is purely a wiring operation so incurs no clock cycles.

Member

a, b & D

Active Participant

A, B, D

Member

Took GregS's suggestion...

This can almost be done with a single function

But checking if the value is ODD is what this really does, so needs the 'NOT' to go EVEN.


Even.png

 

Crossrulz comment about about doing things so that the intention is readable is very important.

Probably all of these would benefit from some comment/explanation alongside them.

 

Member

A, B, D