title: Python outputs strange bytearray
body: <p>Python sometimes generates strange cryptic byte arrays. I have no clue how to interpret them.</p>
  
  <p>Consider the following example.</p>
  
  <pre><code>import struct
  floats = [3.14, 2.7, 0.0, -1.0, 1.1]
  s = struct.pack('f'*len(floats), *floats)
  print("The bytes:")
  print(s)
  </code></pre>
  
  <p>The struct.pack function should output the 'bytes-representation' of each value in the list. The list consists of 64-bit floating point numbers (my computer is 64-bit), so I would expect every float to be represented by 8 bytes:</p>
  
  <pre><code> 3.14 -&gt; 0x40 0x09 0x1E 0xB8 0x51 0xEB 0x85 0x1F
   2.7  -&gt; 0x40 0x05 0x99 0x99 0x99 0x99 0x99 0x9A
   0.0  -&gt; 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
  -1.0  -&gt; 0xBF 0xF0 0x00 0x00 0x00 0x00 0x00 0x00
   1.1  -&gt; 0x3F 0xF1 0x99 0x99 0x99 0x99 0x99 0x9A
  </code></pre>
  
  <p>By the way, I have used the following website to make the proper conversion: <a href="http://babbage.cs.qc.cuny.edu/IEEE-754.old/Decimal.html" rel="nofollow">http://babbage.cs.qc.cuny.edu/IEEE-754.old/Decimal.html</a></p>
  
  <p>Unfortunately, Python does not output those bytes I would expect. Instead, Python outputs some very cryptic list of bytes. But is this really a list of bytes? The thing that Python outputs is so strange:</p>
  
  <pre><code>b'\xc3\xf5H@\xcd\xcc,@\x00\x00\x00\x00\x00\x00\x80\xbf\xcd\xcc\x8c?'
  </code></pre>
  
  <p>Please help me to understand what Python is doing here.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Apparently I should use <code>'d'</code> instead of <code>'f'</code>, since I'm using double precision floating point numbers on my machine. Thank you mr. Rad Lexus for your answer. But I'm still a bit puzzled about the Python outputs. Let me clarify.</p>
  
  <p>I start with the following code that you gave me:</p>
  
  <pre><code>import struct
  floats = [3.14, 2.7, 0.0, -1.0, 1.1]
  s = []
  for f in floats:
      s.append(struct.pack('d', f))
  </code></pre>
  
  <p>Before proceeding, I inspect the object <code>s</code> to get a grasp of what is happening. This is what I get from <code>s</code>:</p>
  
  <pre><code>&gt;&gt;&gt; s
  [ b'\x1f\x85\xebQ\xb8\x1e\t@', 
    b'\x9a\x99\x99\x99\x99\x99\x05@',
    b'\x00\x00\x00\x00\x00\x00\x00\x00', 
    b'\x00\x00\x00\x00\x00\x00\xf0\xbf',
    b'\x9a\x99\x99\x99\x99\x99\xf1?'     ]
  </code></pre>
  
  <p>Some entries in <code>s</code> are 8 bytes long. That is what I would expect. But some entries are shorter. Anyway, there is no entry that gives the correct 8-byte representation of the corresponding float number - except for the float <code>0.0</code>.</p>
  
  <p>Your code continues with some magic to extract the actual correct 8 bytes per float:</p>
  
  <pre><code>print("The bytes:")
  for floatInHex in s:
      for byteval in floatInHex:
          print ('%02x' % byteval, end="")
  </code></pre>
  
  <p>Now we get the correct result. But why is the <code>s</code> object not yet containing the correct 8-bytes per float, to begin with? Why is this extra magic needed?</p>