# IEEE 754 standard - converting 64 bit hex to decimal

**URL:** <https://forum.inductiveautomation.com/t/ieee-754-standard-converting-64-bit-hex-to-decimal/9324>\
**Category:** General Discussion\
**Created:** [November 12, 2014, 1:51pm UTC](https://forum.inductiveautomation.com/t/ieee-754-standard-converting-64-bit-hex-to-decimal/9324 "2014-11-12T13:51:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pstojakovic](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@pstojakovic](https://forum.inductiveautomation.com/u/pstojakovic)\
**Post date:** [November 12, 2014, 1:51pm UTC](https://forum.inductiveautomation.com/t/ieee-754-standard-converting-64-bit-hex-to-decimal/9324/1 "2014-11-12T13:51:58Z")

</div>

Did anyone attempt to convert ieee 754 (64 bit double-precision floating-point ) hex to float using python in Ignition. What are the ways of doing it?

Thanks.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 12, 2014, 3:02pm UTC](https://forum.inductiveautomation.com/t/ieee-754-standard-converting-64-bit-hex-to-decimal/9324/2 "2014-11-12T15:02:52Z")

</div>

Give this a go:

```python
import struct

# Convert IEEE 754 64-bit Hex to Float
hexString="4002c3c9eecbfb16"
print struct.unpack("d", struct.pack("Q",int("0x"+hexString, 16)))[0]

# Convert IEEE 754 64-bit Float to Hex
decVal=2.3456
print hex(struct.unpack("Q", struct.pack("d",decVal))[0])

```

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/011f89db79d1a1a41f1efdfcd2d2e395b9d257ad.png)

---

<div class="post-metadata">

**Author:** ![pstojakovic](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@pstojakovic](https://forum.inductiveautomation.com/u/pstojakovic)\
**Post date:** [November 12, 2014, 4:03pm UTC](https://forum.inductiveautomation.com/t/ieee-754-standard-converting-64-bit-hex-to-decimal/9324/3 "2014-11-12T16:03:45Z")

</div>

Does it do it from right to left or left to right?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 12, 2014, 6:41pm UTC](https://forum.inductiveautomation.com/t/ieee-754-standard-converting-64-bit-hex-to-decimal/9324/4 "2014-11-12T18:41:53Z")

</div>

EDIT: Cleaned up post after migration. 🙂

Left-to-right (big-endian, which is my system default). If you need to specify endianness:

big-endian:

```python
import struct

# Convert IEEE 754 64-bit Hex to Float
hexString="4002c3c9eecbfb16"
print struct.unpack(">d", struct.pack("Q",int("0x"+hexString, 16)))[0]

# Convert IEEE 754 64-bit Float to Hex
decVal=2.3456
print hex(struct.unpack(">Q", struct.pack("d",decVal))[0])

```

little-endian:

```python
import struct

# Convert IEEE 754 64-bit Hex to Float
hexString="4002c3c9eecbfb16"
print struct.unpack("<d", struct.pack("Q",int("0x"+hexString, 16)))[0]

# Convert IEEE 754 64-bit Float to Hex
decVal=2.3456
print hex(struct.unpack("<Q", struct.pack("d",decVal))[0])

```

Checked via online converter:  
[http://babbage.cs.qc.cuny.edu/IEEE-754/](http://babbage.cs.qc.cuny.edu/IEEE-754/)
