|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Least significant bit?
Lionel If the number you want to check is an integer you can simply use the modulus operator % as follows int x, y; y = x%2 If y is 0 then it's even if 1 it's odd. You could also left shift (<<)the value by sizeof(int)-1 and test to see if the result is zero or one. Daniel Daniel >From: Lionel Pinkhard <lionelp@worldonline.co.za> >Reply-To: gameprogrammer@gameprogrammer.com >To: gameprogrammer@gameprogrammer.com >Subject: Least significant bit? >Date: Wed, 26 Jul 2000 11:18:11 +0000 (UTC) > >Hi, > >Can somebody tell me how to check the least significant bit (bit 0) of a >number? > >What I'm trying to do is only to check whether a given number is even or >odd, and (please do correct me if I calculated incorrectly) I think that >all even numbers have 0 as the least significant bit, and all odd numbers >have 1, am I correct? Also, is this > the best/fastest way to do this kind of calculation, or is there >something better? > >I've been thinking of doing this with some kind of AND/OR/XOR mask, but I >think that would get way too complex (after all, I'm only trying to read in >ONE BIT!) > >Kind regards, > >Lionel Pinkhard > >================================================================= >The GameProgrammer.Com mailing list is for the open discussion >of any topic related to the art, science, and business of >programming games. This list is especially tolerant of beginners. >We were all beginners once > >To SUBSCRIBE or UNSUBSCê «¨ please visit: >http://gameprogrammer.com/mailinglist.html ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com ================================================================= The GameProgrammer.Com mailing list is for the open discussion of any topic related to the art, science, and business of programming games. This list is especially tolerant of beginners. We were all beginners once To SUBSCRIBE or UNSUBSCꫨ please visit: http://gameprogrammer.com/mailinglist.html
|
|