Last active
February 24, 2023 12:11
-
-
Save BellCubeDev/c6ee2e98ed2b63bac72ee57a914fbc4a to your computer and use it in GitHub Desktop.
Papyrus function to isolates the specified digits in a number using the given radix.
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
;/ Isolates the specified digits in a number using the given radix. | |
@param hex The number to isolate the digits from. | |
@param firstDigit The index of the first digit to isolate. | |
@param lastDigit The index of the last digit to isolate. Pass `-1` to isolate all digits after firstDigit. | |
@param radix The radix to use. Defaults to 16 for hexadecimal. | |
/; | |
int function isolateDigits(int hex, int firstDigit, int lastDigit, int radix = 16) | |
int firstDigitMult = Math.pow(radix, firstDigit) | |
int placeTooHighVal = Math.pow(radix, lastDigit + 1) | |
return Math.floor(hex / firstDigitMult) % placeTooHighVal | |
endFunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment