Skip to content

Instantly share code, notes, and snippets.

@ppaulojr
Created March 14, 2017 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppaulojr/114b8467e2e07f8692de989693e9183a to your computer and use it in GitHub Desktop.
Save ppaulojr/114b8467e2e07f8692de989693e9183a to your computer and use it in GitHub Desktop.
# input bitset array
# output position of the bits that are 1
def parse_string_netfilter(s):
lista = s.split(",")
resp = []
for i,x in enumerate(lista):
b = "{:b}".format(int(x))[::-1]
resp = resp + [int(j)+1+8*int(i) for j,y in enumerate(b) if y=="1"]
return resp
# Test
parse_string_netfilter("24,16,0,0,0,0")
# Should output [4, 5, 13]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment