Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

IS THERE A FUNCTION TO DETERMINE ODD AND EVEN NUMBERS

Status
Not open for further replies.

BRENTA

Industrial
Feb 2, 2011
8
Hi everyone
I'm in nx6 and trying to create an if/then based on X being odd or even. example if(x==odd)(1)else(0)
Is there such a function or work around?
thanks for your time.
 
Replies continue below

Recommended for you

OK, try this:

test=mod(x,2)

If x is ODD, test=1

If x is EVEN, test=0

Note that 'mod' is known as the 'Modulus' function and is documented in the Expression system's Function section under 'Math'.

John R. Baker, P.E.
Product 'Evangelist'
Product Design Solutions
Siemens PLM Software Inc.
Industry Sector
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
And if there's a chance that 'x' could be positive or negative, it's safer to write the forumla as...

test=mod(abs(x),2)

...as this will remove the effect of the sign of 'x' from the value of 'test'.





John R. Baker, P.E.
Product 'Evangelist'
Product Design Solutions
Siemens PLM Software Inc.
Industry Sector
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
That worked great, thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor