code: def pack_nibbles(nibbles):
      
  
      if nibbles[-1] == NIBBLE_TERMINATOR:
          flags = 2
          nibbles = nibbles[:-1]
      else:
          flags = 0
  
      oddlen = len(nibbles) % 2
      flags |= oddlen   # set lowest bit if odd number of nibbles
      if oddlen:
          nibbles = [flags] + nibbles
      else:
          nibbles = [flags, 0] + nibbles
      o = b''
      for i in range(0, len(nibbles), 2):
          o += ascii_chr(16 * nibbles[i] + nibbles[i + 1])
      return o
docs: pack nibbles to binary
  
      :param nibbles: a nibbles sequence. may have a terminator