× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Why does python's struct think little-endian and big-endian imply different lengths?

Geoffrey Spear
Feb 02, 2015
<p>Specifying <code>'L'</code> without <code>&gt;</code> or <code>&lt;</code> is not "little-endian"; it's native endianness <strong>and</strong> native size. The standard size is 4 bytes, but your machine's native size is 8.</p> <p>If you explicitly want standard sized little-endian, use:</p> <pre><code>struct.unpack('&lt;L', datalen[4:8])[0] </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/25570867/Why%20does%20python's%20struct%20think%20little-endian%20and%20big-endian%20imply%20different%20lengths?/25570906">Stack Overflow</a>.</p>
comments powered by Disqus