Depuis Entier
value = (16).to_bytes(2, 'big') //bytes (ici 2 bytes big endian)
value = str( 16 ) //string
value = hex( 16 ) //hexadecimal
value = bin( 16 ) //binaire (string): 0b10000
value = "{0:08b}".format(16) //binaire (string): 00010000 (8bits)
Depuis Binaire
value = int("11000", 2); //entier
value = hex(int("11000", 2)); //hexadecimal
value = bytes.fromhex( hex( int("11000", 2) )[2:] )
//string (ASCII)
binary_int = int("11000010110001001100011", 2);
byte_number = binary_int.bit_length() + 7 // 8
binary_array = binary_int.to_bytes(byte_number, "big")
value = binary_array.decode()
Depuis Hexadécimal / Hexadécimal (String)
value = bytes.fromhex("ff") //bytes
value = bin( 0xff ) //binaire
value = int( 0xff ) //entier
value = int("eff01dhd", 16) //entier
Depuis String
value = bytes("ABC", 'utf-8') //bytes
value = hex( int("ff", 16) ) //hexadecimal (string)
value = int("55") //entier
Depuis Bytes
value = b'ABC'.decode("utf-8") //string
value = b'ABC'.hex() //hexadecimal
value = int(b'A'.hex(), 16) //entier