CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

anyone have some ideas about detect odds and evens numbers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

anyone have some ideas about detect odds and evens numbers
PostPosted: Sun Oct 22, 2006 12:01 pm     Reply with quote

i need a idea that can detect when a variable is odd or even

like this

if (counter ) = odd
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 22, 2006 12:28 pm     Reply with quote

A couple of ways come to mind right off..
1. Use CCS Bit_test()
2. if ((counter & 1)==1)
kamputty
Guest







PostPosted: Sun Oct 22, 2006 8:34 pm     Reply with quote

Also...use mod

1 % 2 = 1
2 % 2 = 0
3 % 2 = 1
4 % 2 = 0
.
.
.
1=odd
0=even

~Kam (^8*
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 22, 2006 8:49 pm     Reply with quote

See this previous thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=23574&highlight=odd+number
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group