Skip to content

Instantly share code, notes, and snippets.

@tantalor
Created May 13, 2009 16:09
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 tantalor/111103 to your computer and use it in GitHub Desktop.
Save tantalor/111103 to your computer and use it in GitHub Desktop.
def bin(x, k=0):
d = {0:'000', 1:'001', 2:'010', 3:'011', 4:'100', 5:'101', 6:'110', 7:'111'}
return ''.join([d[int(dig)] for dig in oct(x)]).lstrip('0').zfill(k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment