Oh my... > I'm trying to see if the input number is EQUAL > to 3. > > Here's how it works: > > First, I check for divisibility by 3. If the number passes that > test, I then make sure that it's not also divisible by 2. After > that, I use Eric Smith's routine for checking whether a number's > within a certain range... I start with a range of [0-255], then > progressively narrow the range, one step at a time, to [2-4]. > > At this point, if the input number's passed all those tests, I'm > pretty sure that it may be equal to 3. To make ABSOLUTELY sure, > though, I check bits 2-7 of the number individually, verifying > that each is clear, then I check bits 0 and 1 and verify > that they're both set. > > Since this is a very critical aplication, though, even THIS > isn't enough. To get that last little bit of certainty, I > divide 4,294,967,296 by the input number. If the answer's > 1,431,655,765, (with no remainder), I asume that the input > number was indeed equal to 3. > > Finally, I double-check my assumption using the following code: > > XORLW 3 > BZ ITS_EQUAL_TO_3 > > -Andy Andy: You forgot to subtract three from the original input value and then check the zero flag. Only then can you ABSOLUTELY sure. Todd Peterson =========================================================== *** Developers of the PICPlus(TM) Microcontroller Board *** Todd Peterson, Computer Engineer (tpeterson@netins.net) E-LAB Digital Engineering, Inc. P.O. Box 246 Lawton, IA 51030-0246 (712) 944-5344 Visit us at: http://www.netins.net/showcase/elab/ E-Mail Now for Your Free PICPlus(TM) Information Packet! TO: tpeterson@netins.net (include POSTAL mailing address) ===========================================================