Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import struct
  2. a = 5.1
  3. b = 10.0
  4. c = 0.93
  5. d = -4.44
  6.  
  7.  
  8. # byte arrays
  9. ba = bytearray(struct.pack("f", a))
  10. bb = bytearray(struct.pack("f", b))
  11. bc = bytearray(struct.pack("f", c))
  12. bd = bytearray(struct.pack("f", d))
  13.  
  14. byteArray =  ba + bb + bc + bd
  15.  
  16. print byteArray
  17.  
  18.  
  19. offset = 0
  20. unpacked = []
  21. while offset < len(byteArray):
  22.     unpacked.append(struct.unpack_from("f", byteArray[offset:offset+4]))
  23.     offset += 4
  24.  
  25. print unpacked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement