delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/02/15:07:51

Date: Thu, 2 Mar 2000 23:15:25 +0500 (MVT)
From: Prashant TR <prashant_tr AT yahoo DOT com>
X-Sender: prashant_tr AT midpec DOT com
To: djgpp AT delorie DOT com
Subject: Re: odd or even?
In-Reply-To: <38BE28A9.CD476C62@student.kuleuven.ac.be>
Message-ID: <Pine.LNX.4.10.10003022229470.839-100000@midpec.com>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Thu, 2 Mar 2000, 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....

Use bitwise & operator.

if (x & 1) {
	this is odd;
} else {
	this is even;
}

- Raw text -


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