Created
March 14, 2017 20:28
-
-
Save ppaulojr/114b8467e2e07f8692de989693e9183a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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