delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/02/08:28:53

Message-ID: <38BE4B85.1F5A0778@videotron.ca>
From: Trancelucid <trancelucid AT videotron DOT ca>
X-Mailer: Mozilla 4.7 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: odd or even?
References: <38BE28A9 DOT CD476C62 AT student DOT kuleuven DOT ac DOT be>
Lines: 16
Date: Thu, 02 Mar 2000 06:07:49 -0500
NNTP-Posting-Host: 24.201.20.12
X-Complaints-To: abuse AT videotron DOT net
X-Trace: weber.videotron.net 951994880 24.201.20.12 (Thu, 02 Mar 2000 06:01:20 EST)
NNTP-Posting-Date: Thu, 02 Mar 2000 06:01:20 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

DAVID JACOBS wrote:
> 
> What is the fastest way to check wether an int/long is odd or even?
> I've checked my C/C++ manual, but I didn't find anything....

Just mask the bit 0..

if(i & 0x01) {
   printf("odd");
}
else {
   printf("even");
}

	.(Trancelucid).
	  .  Jaune  .

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019