[comp.arch] Div/mod is a slow way to convert binary to decimal

mangler@cit-vax.Caltech.Edu (Don Speck) (07/22/89)

Binary to decimal conversion can be done in hardware almost as
fast as one division by 10.  Rather than subtracting off successive
binary shifts of 10, subtract off the place values of BCD bits
(from a lookup table), starting with the most significant BCD bit.
E.g.
	if (binary > 2000000000) {
		binary -= 2000000000;
		set the bit for 2000000000 in the decimal result
	}
	if (binary > 1000000000) {
		binary -= 1000000000;
		set the bit for 1000000000 in the decimal result
	}
	if (binary > 800000000) {
		binary -= 800000000;
		set the bit for 800000000 in the decimal result
	}
	...

Of course the usual methods of speeding up division (non-restoring,
etc) are applicable here too, and most of the hardware can be shared
with the divider.