Get a matrix of 1's and 0's for character, in Python

Viewed 37

Is there a way to get the bit array of an ASCII character without having to create a dictionary or list with the corresponding rows? only for the letters of the English alphabet, A-Z ASCII TABLE

example:

input : "A"
 
A -> 01000001 -> [[0, 0, 1, 1, 1, 0, 0], ... ]

output: [[0, 0, 1, 1, 1, 0, 0], ... ]

EDIT:

i want

This is what I am looking for, an array with the values ​​to show the figure of the character "A" for example:

# Press Ctrl+f "1" to see this better
[
    [0,0,1,1,1,0,0],
    [0,1,0,0,0,1,0],
    [0,1,0,0,0,1,0],
    [0,1,0,0,0,1,0],
    [0,1,1,1,1,1,0],
    [0,1,0,0,0,1,0],
    [0,1,0,0,0,1,0]
] 
1 Answers

Based on the picture in your post (as far as I am concerned), you can always get the ASCII character using Python built-in function. And if you want to split up the binary strings, you can also use Python join function.

def binary_alphabet_split(astring):
    result = bin(int.from_bytes(astring.encode(), 'big'))
    result = result.replace('b', '')
    return [','.join(result)]

binary_alphabet_split('A')
Out[20]: ['0,1,0,0,0,0,0,1']

This will get you a list of split binary codes of the alphabet.

Related