I need to convert a string into binary, and then convert this binary number into decimal. What I was doing was ask the user for a word, transform each character into a list index, and then convert each index into binary, turn backwards the binary number, and convert into decimal.
Didn't work, and I don't know why. It says that a string has no attribute to_bytes (I don't remember where I saw this syntax, I was searching for a way to convert into binary, and undo it, I think was here in StackOverflow). Can someone help me? Here's the code:
import binascii
senha = list(input("Digite uma frase: "))
senha2 = senha[::-1]
for char in senha2:
char = bin(int.from_bytes(char.encode(), 'big'))
char = char[::-1]
char.to_bytes((char.bit_length() + 7) // 8, 'big').decode()
s='A String'; print int(s.encode('hex'), 16)