Created
August 27, 2018 10:10
-
-
Save maxco2/9ea8d862edbbe00c94ce31c97520c42f to your computer and use it in GitHub Desktop.
python console运算结果32位补码表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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