Skip to content

Instantly share code, notes, and snippets.

@amckinley
Created November 20, 2015 20:14
Show Gist options
  • Save amckinley/4ab697f32a71493832e1 to your computer and use it in GitHub Desktop.
Save amckinley/4ab697f32a71493832e1 to your computer and use it in GitHub Desktop.
def hex_to_bytearray(hex_str):
array_len = ??? # how many bytes do you need for a hex string of length n?
b_arr = bytearray(array_len)
hex_to_decimal = {
"00": 0,
"01": 1,
# etc. dont write this out; find a way to print out this table and then copy/paste it here
}
for idx, char_pair in enumerate(???): # how can you split the hex string into 2-character chunks?
decimal_value = hex_to_decimal[char_pair]
b_arr[idx] = decimal_value
return b_arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment