function d2h(d, digits) {
  d = d.toString(16); 
  while (d.length < digits) {
        d = '0' + d;
    }