[EMAIL PROTECTED] wrote:

> i was wondering if someone could give me a hand on how to test the last
> number ie.

Try this:
For all the bits in the number, add together the last digit of the
decimal value that that bit represents. Do this again with the resulting
number until you have a value < 10. That's your last digit.

Example:

128  64  32  16  8   4   2   1
-------------------------------
 0   1   1   1   0   1   0   1     == 117

Add  4 + 2 + 6     + 4     + 1     == 17

 0   0   0   1   0   0   0   1     == 17

Add          6             + 1     == 7

Hey presto, you've got your number.

Of course, you'll have to test whether that's really faster than doing a
plain old 'x % 10'.

Matthew


-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to