SLUG Mailing List Archives
Re: [SLUG] c++... a bit OT
- To: Some Linux Users Group <slug@xxxxxxxxxxx>
- Subject: Re: [SLUG] c++... a bit OT
- From: Matthew Dalton <matthewd@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed Nov 15 11:49:00 2000
James Wilkinson wrote:
> Well, you could convert it to a string, and look at the last character.
> I think you're going to spend more time in the conversion than you think
> you'd save by using it.
Yeah, that'd work.
> Another way, is to do your computations in binary, then you can mask off
> the last couple of bits. i.e.: 1, 2, 3, 5, 7, 9, B, C, F are prime, you
> can get the last 8 bits of an int by doing something like last8 = num &
This wont work because the higher bits can also contribute to the last
digit of the decimal equivalent.