implement BCD algorithm (cont'd)