How do I convert the integer -2 to its hex 0xfe???
I tried hex() but it gives me -0x2

0xfe is not the hex of -2, it is the hex of 256 - 2. You can use

>>> hex(-2 % 256)
'0xfe'
>>> hex(256 - 2)
'0xfe'

0xfe is not the hex of -2, it is the hex of 256 - 2. You can use

>>> hex(-2 % 256)
'0xfe'
>>> hex(256 - 2)
'0xfe'

Actually, it is for byte.

If I can remember correctly, Windows, -2 is:
Qword (long) = 0xFFFFFFFFFFFFFFFE
Dword (int) = 0xFFFFFFFE
Word (short) = 0xFFFE
Byte = 0xFE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.