Created
May 29, 2020 15:29
-
-
Save evdokimovm/62d8e2ee86ea0e467eda8cbb708becf6 to your computer and use it in GitHub Desktop.
Get nth byte of integer
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
// Get nth byte of integer | |
// https://stackoverflow.com/a/7787433/5526354 | |
int x = (number >> (8*n)) & 0xff; |
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
# Get nth byte of integer | |
# https://stackoverflow.com/a/32695821/5526354 | |
target = 0xd386d209 | |
n = 0 # 0th byte | |
goal = 0xFF << (8 * n) | |
print hex((target & goal) >> (8 * n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment