Skip to content

Instantly share code, notes, and snippets.

@danielpyon
Created October 10, 2022 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpyon/8ada81fa2dc842e8666a63a67c5aa37c to your computer and use it in GitHub Desktop.
Save danielpyon/8ada81fa2dc842e8666a63a67c5aa37c to your computer and use it in GitHub Desktop.
pack a string
def str2bytes(s):
ret = []
for i in range(0, len(s), 8):
sub = s[i:i+8][::-1]
cur = 0
for x in sub:
cur <<= 8
cur |= ord(x)
ret.append(cur)
return ret[::-1]
print(list(map(hex, str2bytes('HTTP/1.0 200 OK\r\n\r\n'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment