You can use struct using the 'd' modifier for 'double':
>>> import struct >>> num1 = '0xb4933333' >>> num2 = '0x41d26580' >>> struct.unpack('!d', (num2[2:]+num1[2:]).decode('hex'))[0] 1234567890.3
Be careful what order you add to doubles, the above suggests a big-end machine. Also, I split 0x since the decode function decode not expect this.
edit: If you are using Python 3, you need to use bytes.fromhex instead of ''.decode('hex') .
Just to give an alternative (the above is a very nice solution):
>>> import struct >>> num1 = '0xb4933333' >>> num2 = '0x41d26580' >>> low_word = int(num1, 16) >>> high_word = int(num2, 16) >>> representation = struct.pack('>II', high_word, low_word) >>> result = struct.unpack('>d', representation) >>> result[0] 1234567890.3
yan
source share