code: func hexToCompact(hex []byte) []byte {
  	terminator := byte(0)
  	if hasTerm(hex) {
  		terminator = 1
  		hex = hex[:len(hex)-1]
  	}
  	buf := make([]byte, len(hex)/2+1)
  	buf[0] = terminator << 5 // the flag byte
  	if len(hex)&1 == 1 {
  		buf[0] |= 1 << 4 // odd flag
  		buf[0] |= hex[0] // first nibble is contained in the first byte
  		hex = hex[1:]
  	}
  	decodeNibbles(hex, buf[1:])
  	return buf
  }
docs: // Trie keys are dealt with in three distinct encodings:
  //
  // KEYBYTES encoding contains the actual key and nothing else. This encoding is the
  // input to most API functions.
  //
  // HEX encoding contains one byte for each nibble of the key and an optional trailing
  // 'terminator' byte of value 0x10 which indicates whether or not the node at the key
  // contains a value. Hex key encoding is used for nodes loaded in memory because it's
  // convenient to access.
  //
  // COMPACT encoding is defined by the Ethereum Yellow Paper (it's called "hex prefix
  // encoding" there) and contains the bytes of the key and a flag. The high nibble of the
  // first byte contains the flag; the lowest bit encoding the oddness of the length and
  // the second-lowest encoding whether the node at the key is a value node. The low nibble
  // of the first byte is zero in the case of an even number of nibbles and the first nibble
  // in the case of an odd number. All remaining nibbles (now an even number) fit properly
  // into the remaining bytes. Compact encoding is used for nodes stored on disk.