Skip to content

Instantly share code, notes, and snippets.

@auxiliary
Last active September 23, 2016 23:04
Show Gist options
  • Save auxiliary/60c9ac057c0f1fc23a4e1b55ae8fbbd8 to your computer and use it in GitHub Desktop.
Save auxiliary/60c9ac057c0f1fc23a4e1b55ae8fbbd8 to your computer and use it in GitHub Desktop.
# In case you need byte arrays
import numpy as np
a = np.uint64(7640891576956014592) #64 bits
b = a.tostring() # '\x00\xd0\xbc\xf3g\xe6\tj' in bytes
b = bytearray(b) # bytearray(b'\x00\xd0\xbc\xf3g\xe6\tj') Byte array object
# Padding
a = [1, 1, 1, 1, 1]
a + [0] * (16 - len(a)) # [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# From string of text into padded bytes
s = 'abc'
s = s + chr(0) * (128 - len(s))
b = struct.unpack('<16Q', s)
#Packing
struct.pack('<16Q', *b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment