| View previous topic :: View next topic |
| Author |
Message |
biotech as guest Guest
|
Posted: Mon Jan 21, 2008 10:57 pm Post subject: divisiable by four? easy for gurus |
|
|
i need to know is number divisable by four, if it is not what first greater one is?
this should be easy for serious programers, which i am not.
any hints?
thanks |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 906
|
Posted: Mon Jan 21, 2008 11:23 pm Post subject: |
|
|
| Code: | X := 15
If (Mod(X, 4) = 0)
MsgBox % X . " is divisible by four."
Else
{
Y := X + 4 - Mod(X, 4)
MsgBox % X . " is not divisible by four, but " . Y . " is."
} |
|
|
| Back to top |
|
 |
dncarac
Joined: 31 Aug 2006 Posts: 64
|
Posted: Mon Jan 21, 2008 11:28 pm Post subject: |
|
|
Bitwise exclusive-OR the number with 3, then check if the result is zero. If so, the number is divisible by four, if not, it is not.
To find the next higher number divisible-by-four, bitwise shift the original number right two bits then bitwise shift the result left by two bits. The result of that operation is the next higher number divisible-by-four.
There are other methods.
All of these operations are described in the documentation under "Variables and Expressions"
DNC |
|
| Back to top |
|
 |
|