def pack_nibbles(nibbles):
 if (nibbles[(-1):] == [NIBBLE_TERMINATOR]):
  flags = 2
  nibbles = nibbles[:(-1)]
 else:
  flags = 0
 oddlen = (len(nibbles) % 2)
 flags |= oddlen
 if oddlen:
  nibbles = ([flags] + nibbles)
 else:
  nibbles = ([flags, 0] + nibbles)
 o = ''
 for i in range(0, len(nibbles), 2):
  o += ascii_chr(((16 * nibbles[i]) + nibbles[(i + 1)]))
 return o

def pack_nibbles ( nibbles ) : if ( nibbles [ ( - 1 ) : ] == [ NIBBLE_TERMINATOR ] ) : flags = 2 nibbles = nibbles [ : ( - 1 ) ] else : flags = 0 oddlen = ( len ( nibbles ) % 2 ) flags |= oddlen if oddlen : nibbles = ( [ flags ] + nibbles ) else : nibbles = ( [ flags , 0 ] + nibbles ) o = '' for i in range ( 0 , len ( nibbles ) , 2 ) : o += ascii_chr ( ( ( 16 * nibbles [ i ] ) + nibbles [ ( i + 1 ) ] ) ) return o
pack nibbles to binary .