View Single Post
  #10   Spotlight this post!  
Unread 05-01-2008, 10:40
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: How does division work?

Quote:
Originally Posted by JoeXIII'007 View Post

Side note somewhat related: The modulus (%) operator is amazingly useful if you want to find the remainder, for that is what it does. Its even more useful for determining if a given integer is odd or even given you divide by 2 (Example: 66 % 2 gives you 0 since it is even, 65 % 2 gives you 1 since it is odd).
A more efficient way of checking oddness or even-ness is to use bitwise AND with 1 (though a smart compiler will probably do this anyway).

Bitwise AND ands together each binary digit of the two inputs.

4 & 1 = 0
5 & 1 = 1
6 & 1 = 0

Binary example:
5 & 1:
0011 <-- 5
0001 <-- 1
0001 <-- 5 & 1