Skip to content

Instantly share code, notes, and snippets.

@andfoy
Created August 15, 2014 21:24
Show Gist options
  • Save andfoy/600419fed628745d1c97 to your computer and use it in GitHub Desktop.
Save andfoy/600419fed628745d1c97 to your computer and use it in GitHub Desktop.
def splitNum(Nd):
N = bin(Nd)[2:]+'0'
cant = 0
d = {}
for i in range(0, len(N)-1):
if int(N[i]) == 1:
d[cant] = i
cant += 1
a = list('0'*(len(N)-1))
b = list(a)
for i in range(1, len(d.keys()), 2):
a[d[i]] = '1'
for i in range(0, len(d.keys()), 2):
b[d[i]] = '1'
a = int(''.join(a), 2)
b = int(''.join(b), 2)
return [a, b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment