AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

divisiable by four? easy for gurus

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
biotech as guest
Guest





PostPosted: Mon Jan 21, 2008 10:57 pm    Post subject: divisiable by four? easy for gurus Reply with quote

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

PostPosted: Mon Jan 21, 2008 11:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
dncarac



Joined: 31 Aug 2006
Posts: 64

PostPosted: Mon Jan 21, 2008 11:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group