def _gen_rules_port_min(port_min, top_bit):
 rules = []
 mask = (top_bit - 1)
 while True:
  if ((port_min & mask) == 0):
   rules.append(_hex_format(port_min, mask))
   break
  top_bit >>= 1
  mask >>= 1
  if ((port_min & top_bit) == 0):
   rules.append(_hex_format(((port_min & (~ mask)) | top_bit), mask))
 return rules

def _gen_rules_port_min ( port_min , top_bit ) : rules = [ ] mask = ( top_bit - 1 ) while True : if ( ( port_min & mask ) == 0 ) : rules . append ( _hex_format ( port_min , mask ) ) break top_bit >>= 1 mask >>= 1 if ( ( port_min & top_bit ) == 0 ) : rules . append ( _hex_format ( ( ( port_min & ( ~ mask ) ) | top_bit ) , mask ) ) return rules
encode a port range range(port_min .