Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] c++... a bit OT

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 &
> 0xF

This wont work because the higher bits can also contribute to the last
digit of the decimal equivalent.