<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Read float (single precision) from binary in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347756#M69202</link>
    <description>&lt;P&gt;It's not possible to represent 1.2000000000 in floating point representation. That's just how IEEE-754 works.&lt;/P&gt;&lt;P&gt;There's lots of&amp;nbsp; web sites that show this, but &lt;A href="https://www.h-schmidt.net/FloatConverter/IEEE754.html" target="_blank" rel="noopener"&gt;this is the one I used&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2023 16:25:07 GMT</pubDate>
    <dc:creator>VinceAngelo</dc:creator>
    <dc:date>2023-11-09T16:25:07Z</dc:date>
    <item>
      <title>Read float (single precision) from binary</title>
      <link>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347735#M69199</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to retrieve some float values from a blob field.&lt;/P&gt;&lt;P&gt;My workflow is get the blob field as text (hex) and parse it.&lt;/P&gt;&lt;P&gt;I can parse it no problem, but the issue is that the floats are returning what they're actually stored as, e.g. 1.2 is actually&amp;nbsp;1.2000000476837158203125, etc.&lt;BR /&gt;I can't round because each float has a different number of significant digits.&lt;/P&gt;&lt;P&gt;Weirdly enough, doubles parsed analogously come exactly as they should.&lt;/P&gt;&lt;P&gt;Does anyone have any ideas of how to get the correct values?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'''Float (single precision)'''
a = binVal[6:8] + binVal[4:6] + binVal[2:4] + binVal[0:2]
print(a)
# 3F99999A
domCd = struct.unpack('!f', bytes.fromhex(a))[0] 
print(domCd)
# 1.2000000476837158

'''Double (double precision)'''
a = (binVal[14:16] + binVal[12:14] + binVal[10:12] + binVal[8:10] +
     binVal[6:8] + binVal[4:6] + binVal[2:4] + binVal[0:2])
print(a)
# 3FF3333333333333
domCd = struct.unpack('!d', bytes.fromhex(a))[0] 
print(domCd)
# 1.2&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Nov 2023 15:46:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347735#M69199</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-11-09T15:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Read float (single precision) from binary</title>
      <link>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347756#M69202</link>
      <description>&lt;P&gt;It's not possible to represent 1.2000000000 in floating point representation. That's just how IEEE-754 works.&lt;/P&gt;&lt;P&gt;There's lots of&amp;nbsp; web sites that show this, but &lt;A href="https://www.h-schmidt.net/FloatConverter/IEEE754.html" target="_blank" rel="noopener"&gt;this is the one I used&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 16:25:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347756#M69202</guid>
      <dc:creator>VinceAngelo</dc:creator>
      <dc:date>2023-11-09T16:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Read float (single precision) from binary</title>
      <link>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347759#M69203</link>
      <description>&lt;P&gt;Yes, I understand that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the GUI that can read this field natively (read: arcmap) can pull the correct values, so how can I?&lt;/P&gt;&lt;P&gt;Also, as I understand it, neither can doubles, and yet...&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 16:29:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-float-single-precision-from-binary/m-p/1347759#M69203</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-11-09T16:29:06Z</dc:date>
    </item>
  </channel>
</rss>

