Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

how to tell if an integer is even or odd

Status
Not open for further replies.

Nuqe

Technical User
May 6, 2003
57
0
0
CA
I'm looking for a way to determine if an integer is even or odd. i'm doing a print procedure and need to take the number of records in a database and half it, then print each half on different pages. This is easy unless you have an odd number. If i can determine if the recordcount is odd then i can just add 1 as a place holder so i can do the procedure.

any help would be appreciated
NUQE

We all know about the "stupid user" don't we... :)
 
Yes, you're right....

And this makes me wonder exactly how VB compiles the two; either it's compiling mod 2 very cleverly or it's compiling AND rather "stupid"....

Greetings,
Rick
 
Tested CCLINT's code on my home PC. (Not the one I used to experiment earlier.)

Here are the results with loop count set to 100 million.
[tt]
Count = 100,000,000
AND MOD
VBIDE 16.926 24.327
EXE 0.6904 0.4596
[/tt]
Then I change the loop count to 10 million and got the following results.
[tt]
Count = 10,000,000
AND MOD
VBIDE 1.695 2.437
EXE 0.06984 0.04616
[/tt]

Conclusion:

Apparently, it looks that AND is faster in VBIDE and MOD is faster with compiled EXE.

I used native compilation with fast code having all advanced optimization options removed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top