<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Topics tagged with bytearray]]></title><description><![CDATA[A list of topics that have been tagged with bytearray]]></description><link>https://forum.pycom.io/tags/bytearray</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 14:33:29 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/tags/bytearray.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Jan 2018 09:25:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Bytearray() and structures for floating point values]]></title><description><![CDATA[I found an answer.   The function in Python by default packs the four bytes in little endian format.  JavaScript expects big endian.  By merely changing
data = bytearray(struct.pack(&quot;f&quot;, vt))  
to
data = bytearray(struct.pack(&quot;&gt;f&quot;, vt))  
the unpack at the other end was simple.
Java Script
function decodeFloat(data1) {
    var binary = parseInt(data1, 16).toString(2);
    if (binary.length &lt; 32) 
        binary = ('00000000000000000000000000000000'+binary).substr(binary.length);
    var sign = (binary.charAt(0) == '1')?-1:1;
    var exponent = parseInt(binary.substr(1, 8), 2) - 127;
    var significandBase = binary.substr(9);
    var significandBin = '1'+significandBase;
    var i = 0;
    var val = 1;
    var significand = 0;

    if (exponent == -127) {
        if (significandBase.indexOf('1') == -1)
            return 0;
        else {
            exponent = -126;
            significandBin = '0'+significandBase;
        }
    }

    while (i &lt; significandBin.length) {
        significand += val * parseInt(significandBin.charAt(i));
        val = val / 2;
        i++;
    }

    return sign * significand * Math.pow(2, exponent);
}


// example use
data = '408df220' // is floating point value 4.43580627441406255
value = decodeFloat(data);
log.console('Value=', value);

The code above is from https://stackoverflow.com/questions/4414077/read-write-bytes-of-float-in-js
From a great website application at https://gregstoll.dyndns.org/~gregstoll/floattohex/ I produced the image below

]]></description><link>https://forum.pycom.io/topic/2468/bytearray-and-structures-for-floating-point-values</link><guid isPermaLink="true">https://forum.pycom.io/topic/2468/bytearray-and-structures-for-floating-point-values</guid><dc:creator><![CDATA[smbunn]]></dc:creator><pubDate>Wed, 17 Jan 2018 09:25:15 GMT</pubDate></item><item><title><![CDATA[bytearray, type and format confusion]]></title><description><![CDATA[@soren Add ```  alone on the lines before and after your code, or prefix them all with 4 spaces to have them formatted as code.
40000 % 256 (or 40000 &amp; 255, i.e. keeping the 8 least significant bits) = 64, which is the code point for @.
]]></description><link>https://forum.pycom.io/topic/2058/bytearray-type-and-format-confusion</link><guid isPermaLink="true">https://forum.pycom.io/topic/2058/bytearray-type-and-format-confusion</guid><dc:creator><![CDATA[jcaron]]></dc:creator><pubDate>Tue, 31 Oct 2017 16:03:13 GMT</pubDate></item></channel></rss>