I know that there is a function

bin(x) 

But it makes from the number - binary code. Is there any way to translate or do I need to write a separate code for this ???

  • under the binary code is the string? - Grundy
  • Since the "binary code" in the header is ambiguous: it can refer to strings in the binary system (contains only the characters "01") and to byte strings (binary data such as a picture, archive). The first as in the body of the question: the operation inverse to bin() is int(bits,2) . Second: int.from_bytes(b"\x73\x6f", 'big')==29551 - jfs

1 answer 1

If by binary code you mean a string, then the built-in int() function has an optional base argument, which indicates the reason for writing the number in the string:

 >>> bin(123) '0b1111011' >>> int('1111011', 2) 123