Created
October 10, 2022 00:50
-
-
Save danielpyon/8ada81fa2dc842e8666a63a67c5aa37c to your computer and use it in GitHub Desktop.
pack a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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