Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Odd or Even Program Problem
#11
Hybr!d, If you dont understand the MOD method, you could try this little one:

[syntax="qbasic"]if number / 2 = number \ 2 then #its even!# else #its odd!#[/syntax]

Basically it checks if the number / 2 is a whole number by comparing it to the equivalent integer calculation (which is always rounded to the nearest whole number). If the number is even, both calculations will produce the same result, however if the number is odd, the floating point divide will produce non-whole number and the integer division will produce a whole number and they wont match.
Reply
#12
Quote:.....
Minor correction: ANDing by 1 will never result in -1.
Your absolutely right, Sterling.
In this case of ANDing with 1, if the number is odd, the result will actually be 1, which is treated as TRUE since anything other that zero is TRUE. FALSE of course is always zero.

Thanks for bringing this up because many people get TRUE results mixed up.
*****
Reply
#13
Quote:Dio:
Sorry, it didn't occur to me that was a username, I thought you were making a joke. :oops:

stylin Wrote:[...] returns true (-1) [...]
Minor correction: ANDing by 1 will never result in -1.

don't worry, it happends to the best of us. Big Grin
when i read your other post i was thown into cardiac arrest because i thought I made a mistake. :o
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Reply
#14
Quote:Thanks for bringing this up because many people get TRUE results mixed up.
*****
Yes, they do. :wink:
stylin:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)