Skip to content

Instantly share code, notes, and snippets.

@JamesTheAwesomeDude
Created May 22, 2018 16:27
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 JamesTheAwesomeDude/fd84d821c2131474b5df2c41150521b9 to your computer and use it in GitHub Desktop.
Save JamesTheAwesomeDude/fd84d821c2131474b5df2c41150521b9 to your computer and use it in GitHub Desktop.
Quick base2 encode
# from base2 import b2 as int_base2_repr
# int_base2_repr()
b2 = lambda i,p=8:'0b{0:0{1}b}'.format(i, p)
assert b2(6,4) == '0b0110' and b2(127) == '0b01111111'
# WARNING: "overflows" will OVERRIDE the length specifier
# and return a string that may be longer than you were expecting.
# You should double-check the returned string length yourself
# if this is a concern for you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment