Skip to content

Instantly share code, notes, and snippets.

@maxco2
Created August 27, 2018 10:10
Show Gist options
  • Select an option

  • Save maxco2/9ea8d862edbbe00c94ce31c97520c42f to your computer and use it in GitHub Desktop.

Select an option

Save maxco2/9ea8d862edbbe00c94ce31c97520c42f to your computer and use it in GitHub Desktop.
python console运算结果32位补码表示
def display_as_hex(item):
def int2hex(number, bits):
if number < 0:
return hex((1 << bits) + number)
else:
return hex(number)
if isinstance(item, (int, long)):
print(int2hex(item,32))
else:
print repr(item)
import sys
sys.displayhook=display_as_hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment