Created
May 22, 2018 16:27
-
-
Save James-E-A/fd84d821c2131474b5df2c41150521b9 to your computer and use it in GitHub Desktop.
Quick base2 encode
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
# 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