divmod10() : a fast replacement for /10 and %10 (unsigned)

I'm not sure that:

x = q;
q= (q>>16) + (x>>8) + x;

is a valid substitution for

x = q
q= (q>>8) + x;
q= (q>>8) + x;

take q = 0x00000FFF

In your substitution:

x = 0x00000FFF
q = 0x00000000 + 0x0000000F + 0x00000FFF = 0x0000100E

In the original:

x = 0x00000FFF
q = 0x0000000F + 0x00000FFF = 0x0000100E
q = 0x00000010 + 0x00000FFF = 0x0000100F

Notice the discrepancy? Its because you lost a vital carried bit.

genom2:
Can manually coded assembler do the job? (Which is not in my scope.)

I have been :slight_smile: