def StringToBinary(data: str): return str(''.join(format(ord(i), '08b') for i in data)) def BinaryToDecimal(data: str): data1 = data //data1 is unused, no idea why they did this decimal, i, n = 0, 0, 0 //n is again unused while (data != 0): dec = data % 10 decimal = decimal + dec * pow(2, i) data = data//10 i += 1 return (decimal) def BinaryToString(data: str): str_data = " " for i in range(0, len(data), 7): temp_data = int(data[i:i + 7]) decimal_data = BinaryToDecimal(temp_data) str_data = str_data + chr(decimal_data) return str_data string0 = StringToBinary("Geeks") string1 = BinaryToString(string0) print(string0) print(string1)
0100011101100101011001010110101101110011 #Y,V[!!
0100011101100101011001010110101101110011 Geeks
for i in range(0, len(data), 7): temp_data = int(data[i:i + 7])
for i in range(0, len(data), 8): temp_data = int(data[i:i + 8])
return str(''.join(format(ord(i), '08b') for i in data))
return str(''.join(format(ord(i), '07b') for i in data))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)