the original code from http://lbd.udc.es/research/DACS/
fix a hidden bug which will surface when the first level is great than 16 bit. see the test data.