I’m trying to finish a program that converts text2bin and bin2text among other things, but I have a problem with the bin2text function, but only with some characters.
This is the part that is giving me problems:
def bin2text(self):
cadena2=' '
self.ventana.caja1.text()
split=[self.ventana.caja1.text()[x:x+8] for x in range(0,len(self.ventana.caja1.text()),8)]
for i in splits:
cadena2=cadena2+chr(int(i,2))
self.ventana.caja2.setText(cadena2)
I’m getting the error:
Invalid literal for int() with base 2 '100000 1.... '
on the line
cadena2=cadena2+chr(int(i,2))
(The ellipses dots aren’t actually a part of the error but there’s an arrow in the way in the figure)
when I try to go from binary to text, using “space” or any sign that the passing of ASCII to Bin, the number consists of six digits, I get the error. Seven or eight digit numbers work.
I need to know a how to add a 0 at the beginning of this series(0100000), to fix it
See figures below:



try this:
The problem is not the number of digits, the problem is the whitespace within the string you sent to ‘int’