Last active
July 9, 2019 11:40
-
-
Save MrSuicideParrot/b9dfdb97afd2f8105693b2622b25cfd9 to your computer and use it in GitHub Desktop.
Convert a packed byte string to an int array in python2
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
import struct | |
def pack_hex_to_int_arr(hex_str): | |
arr = [] | |
for i in hex_str: | |
arr.append(struct.unpack("B", i)[0]) | |
return arr | |
if __name__ == "__main__": | |
test = "\xfcg\xb2I\x00\x00\x00\x00s\x0e@\x00\x00\x00\x00\x00\x18 `\x00\x00\x00\x00\x00\x8c\x06@\x00\x00\x00\x00\x00w\x0c@\x00\x00\x00\x00\x00" | |
result = [252, 103, 178, 73, 0, 0, 0, 0, 115, 14, 64, 0, 0, 0, 0, 0, 24, 32, 96, 0, 0, 0, 0, 0, 140, 6, 64, 0, 0, 0, 0, 0, 119, 12, 64, 0, 0, 0, 0, 0] | |
print(pack_hex_to_int_arr(test) == result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment