I use python 2.6
>>> hex(-199703103)
'-0xbe73a3f'
>>> hex(199703103)
'0xbe73a3f'
Positive and negative value are the same?
When I use calc, the value is FFFFFFFFF418C5C1.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Python’s integers can grow arbitrarily large. In order to compute the raw two’s-complement the way you want it, you would need to specify the desired bit width. Your example shows
-199703103in 64-bit two’s complement, but it just as well could have been 32-bit or 128-bit, resulting in a different number of0xf‘s at the start.hex()doesn’t do that. I suggest the following as an alternative:This prints out: