Created
May 20, 2019 18:56
-
-
Save BurhanH/b577258e2ddf78ffd980bb2c67cb2bf5 to your computer and use it in GitHub Desktop.
Convert a character into 8 bits (https://realpython.com/python-encodings-guide/)
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
# python 3.7 | |
def make_bitseq(s: str) -> str: | |
if not s.isascii(): | |
raise ValueError("ASCII only allowed") | |
return " ".join(f"{ord(i):08b}" for i in s) | |
make_bitseq("bits") | |
# '01100010 01101001 01110100 01110011' | |
make_bitseq("CAPS") | |
# '01000011 01000001 01010000 01010011' | |
make_bitseq("$25.43") | |
# '00100100 00110010 00110101 00101110 00110100 00110011' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment