Last active
February 27, 2022 21:26
-
-
Save alimsk/4b5a66268376eec1e7a4b419b154d7f4 to your computer and use it in GitHub Desktop.
python calculate EXTENDED_ARG
This file contains 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
print(split_arg(270)) | |
# output: | |
# (14, 1, 0, 0) | |
# when used: | |
# EXTENDED_ARG 1 | |
# JUMP_ABSOLUTE 14 |
This file contains 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
import typing as t | |
def split_arg(value: int) -> t.Tuple[int, int, int, int]: | |
first, value = divmod(value, 256) | |
second, first = divmod(first, 256) | |
last, second = divmod(second, 256) | |
if last >= 256: | |
raise ValueError(f"too big numbers, max is 32 bit") | |
return value, first, second, last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment