Reputation: 12394
I am working with "Learn Python the Hard Way".
On Page 82 there is a hexadecimal
encoded string.
rawBytes = b'\xe6\x96\x87\xe8\xa8\x80'
When I try to convert only one hexadecimal
value to decimal
value
int(0xxe6)
I get the error
SyntaxError: invalid hexadecimal literal
Why is that?
Upvotes: 0
Views: 274
Reputation: 3974
Hexadecimal values are composed of numbers 0-9 and/or A to F. You are using the letter 'x' twice in a row which causes the error. The escape sequence in the byte literal '\x' has the same meaning as '0x'. So try int(0xe6)
and you are golden.
Upvotes: 1