I have a string of bytes like str_of_bytes = b'\x20\x64\x20'
, of which I want to extract, say, the second element.
If I do str_of_bytes[1]
, what I get is the int
100
.
How do I just get b'\x64'
, without having to reconvert the int
to bytes
?
Extract it as a range:
str_of_bytes[1:2]
Result:
b'd'
This is the same as b'\x64'
Note that I'm assuming you're using Python 3. Python 2 behaves differently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With