The Daily CLAD

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

Re: CLAD2017 - Answer the Requirement - Even Stevens

SercoSteveB
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
Comments
dilipa
Member

a,b & D

sankar06
Member

A,B, & D

Happy to Wire
crossrulz
Knight of NI

A, B, D

 

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


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
N3MRA
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
crossrulz
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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
GregSands
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.

SPK91
Member

a, b & D

mini09
Active Participant

A, B, D

Timsrice
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.

 

levonsg
Member

A, B, D

https://images.youracclaim.com/size/340x340/images/2edb5b1a-9414-44e1-8519-c774fc6dd079/36015_Certificate_Badges_FINAL__1__NI_Instructor_v5.png
kirti3105
Member

A, B and D will give correct output. But A is the simplest and easiest way rather than B and D

Krishna_kp
Member

Hi all,

for zero also these methods will give output as TRUE (even number).

whether zero is an even number? 

crossrulz
Knight of NI

Per wikipedia, 0 is even.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
istan0227
Member

ABD