バイナリデータ↔ASCIIデータ

import binascii


a = b'0111000001101100011001010110000101110011011001010010000001100110011010010110111001100100001000000110110101100101'
print(''.join(chr(int(a[i*8:(i+1)*8], 2)) for i in range(len(a)//8)))

print(binascii.unhexlify(f'{int(a, 2):x}'))
please find me
b'please find me'
b = 'please find me'
''.join(bin(ord(s)) for s in b)#''.join(f'{ord(s):#b}' for s in b)

‘111000011011001100101110000111100111100101100000110011011010011101110110010010000011011011100101’

''.join(f'{ord(s):b}' for s in b)

‘111000011011001100101110000111100111100101100000110011011010011101110110010010000011011011100101’

カテゴリー: 未分類 パーマリンク