× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I guess I should read my own emails... It should be...

0123 4567
xxxx x1xx

If  %bitAnd(X'10' : lastByteOfNum) 
//  value is odd.
Endif

-Bob Cozzi
www.RPGxTools.com
RPG xTools - Enjoy programming again.


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Bob Cozzi
Sent: Tuesday, October 18, 2005 8:52 AM
To: 'RPG programming on the AS400 / iSeries'
Subject: RE: Checking for an odd number

TESTB in /FREE
Something like this, but I don't have the exact syntax in front of me...

0123 4567
xxxx x1xx

If  %bitAnd(X'04' : lastByteOfNum) 
//  value is odd.
Endif


-Bob Cozzi
www.RPGxTools.com
RPG xTools - Enjoy programming again.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of dkahn@xxxxxxxxxxxxxxxxx
Sent: Tuesday, October 18, 2005 5:33 AM
To: RPG programming on the AS400 / iSeries
Subject: Re: Checking for an odd number





"D.W." <dpalme@xxxxxxxxxxx> wrote:

> I have a need to determine whether or not a numeric value is an
> even or odd number when cycling through a PF..
>
> Is there a simple way to accomplish this within RPG without having
> to resort to some complicated mathematical formula?

Just for giggles here is a quirky and old-fashioned but highly efficient
way to do it. It seems to be about ten times faster than the
remainder-from-divide-by-2 method. It has to be in traditional format as
TESTB is not supported in free. In this case the number to be tested is
packed decimal. If it is zoned or binary, factor 2 of the TESTB operation
would need to be '7'.

*************** Beginning of data *************************************
d                 ds
d num                     1      3p 0
d  lastByteOfNum          3      3a
d numberIsOdd     s               n

c                   for       num = -10 to 10
c                   testb     '3'           lastByteOfNum            30
c                   eval      numberIsOdd = *in30

c                   if        numberIsOdd
c     'odd'         dsply                   num
c                   else
c     'even'        dsply                   num
c                   endif

c                   endfor

c                   eval      *inlr = *on
****************** End of data ****************************************

--
Dave...
               _________  ,___o
             __________   _\ <;_        http://www.audax.uk.net
           ___________   (_)/ (_)       http://www.twickenhamcc.co.uk
=======================================================
The opinions expressed in this communication are my own and do not
necessarily reflect those of my employer.


______________________________________________________________________
This message may contain confidential information which may also be legally
privileged and is intended only for the use of the parties to whom it is
addressed. If you are not an intended recipient you are hereby notified that
any disclosure, copying, distribution or use of any information in this
e-mail is strictly prohibited. If you receive this message in error please
notify the sender by return e-mail and then destroy it. Further, we make
every endeavour to keep our network free from viruses. However, you do need
to verify that this e-mail and any attachments are free of viruses as we can
take no responsibility for any computer viruses which might be transferred
by way of this e-mail. All information and attachments remain the property
of Stolt Offshore Group and should be held as confidential.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.