Reputation: 13
I'm converting some code from python 2.7 to python 3 and I am running into issues with hexadecimal ints.
value = 0x11
hexdump(value)
python2 output: 11
python3 output: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
This hexdump function is from scapy and has worked for all my other hex troubleshooting. Doing chr(0x11) yields the expected value but many scapy functions get called that crash if it's not in type int.
I need a way to get 11 as my hex data with type int. I tried changing the type using
int(value,16) #also tried 0 and 10
The issue with this is I get ValueError: invalid literal for int() with base 10: '\x11'
Upvotes: 0
Views: 267
Reputation: 6338
0x11
is an int in both python2 and python3. Perhaps there's some string-handling in your hexdump
function that's going wrong? Strings are very different in python3.
Can you post the code for hexdump()
?
Based on the comment below by @Cukic0d, if your hexbytes()
actually wants an array of bytes, this should work: hexdump(bytes([value]))
-- that converts the length-1 array of ints containing value into a bytes
object and passes that to hexdump
.
Upvotes: 2