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

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