Reputation: 21
Given the string: aa0a051c1400
, how would I go about extracting just 05
or the 1c
? I'm reading serial responses and I need to examine fragments of hex data to decipher what how much data is coming down the pipe after this initial data packet.
Upvotes: 1
Views: 815
Reputation: 6606
Just parsing the string by index works fine. If you want to parse by character index:
from binascii import hexlify, unhexlify
def get_hex(stream, idx):
return hexlify(unhexlify(stream)[idx])
get_hex('aa0a051c1400', 0)
'aa'
Upvotes: 1