Skip to content

Instantly share code, notes, and snippets.

@acmiyaguchi
Last active December 17, 2015 20:19
Show Gist options
  • Save acmiyaguchi/ff4403ca07e680678a9f to your computer and use it in GitHub Desktop.
Save acmiyaguchi/ff4403ca07e680678a9f to your computer and use it in GitHub Desktop.
#########################################
# bitmapfont.py #
# #
# Display C-style bitmap fonts in text #
#########################################
import re
def main():
inputline = raw_input("Enter the bytes: ")
print_width = 5
#Match consective hexdecimal digits and return a list
bytelist = re.findall('[0-9a-f]{2}', inputline.lower())
#convert bytes from hex to binary
hex_scale = 16
num_bits = 8
bytelist = [bin(int(byte, hex_scale))[2:].zfill(num_bits) for byte in bytelist]
byte_len = len(bytelist)/print_width
for y in range(0,8):
printline = ''
for bit in bytelist:
if int(bit[y]) == 1:
printline += '#'
else:
printline += ' '
print(printline)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment