code: function toHex(i) {
      var hex;
  
      if (i < 0) {
          i += 256;
      }
      hex = i.toString(16);
  
      // zero padding
      if (hex.length == 1) {
          hex = "0" + hex;
      }
      return hex;
  }
docs: i must be <= 256