code: function encodeLengthHex(n) {
      if (n<=127) return toHex(n)
      else {
          var n_hex = toHex(n)
          var length_of_length_byte = 128 + n_hex.length/2 // 0x80+numbytes
          return toHex(length_of_length_byte)+n_hex
      }
  }
docs: encode ASN.1 DER length field if <=127, short form if >=128, long form