Advertisement
ibobah

Hex-text to raw data

Apr 5th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # Make from/to text DEADFACE raw data DEADFACE
  2. #
  3. # 1st way
  4. #
  5.  
  6. import struct
  7.  
  8. # 1
  9. hex_str = "DEADFACE"
  10.  
  11. # create int
  12. a = int(hex_str, 16)
  13. b = st.pack("L", a)
  14. # b == '\xce\xfa\xad\xde\x00\x00\x00\x00'
  15.  
  16. # 2nd way
  17. #
  18.  
  19. import binascii as b2a
  20.  
  21. hex_str = "DEADFACE"
  22. res = b2a.unhexlify(hex_str)
  23. # res =='\xde\xad\xfa\xce'
  24.  
  25.  
  26. # 3rd way
  27.  
  28. import binascii as b2a
  29.  
  30. a = 8037
  31. b = hex(a)
  32. # b == '\x1F65'
  33.  
  34. b = b[2:].replace("L", "")
  35. # b == '1F65'
  36.  
  37. res = b2a.unhexlify(b)
  38. # res =='\x1f\x65'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement