Skip to content

Instantly share code, notes, and snippets.

@BellCubeDev
Last active February 24, 2023 12:11
Show Gist options
  • Save BellCubeDev/c6ee2e98ed2b63bac72ee57a914fbc4a to your computer and use it in GitHub Desktop.
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.
;/ 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