I'm looking for a function that will determine the value of a place given a number and a base. For example,
Given:
Whole Value: 1120 Base: 10 Place: Tens place
Should return: 2
Does anybody know the math for this?
Edit: The function is also expected to pass the whole value numerically, not as a string like "e328fa" or something. Also the return value should be numeric as well, so a FindInPlace(60 (whole value), 16 (base), 2 (place, 1-based index)) should return 3.
With 1-based place indexing the formula is:
placeval = floor(number / (base^(place-1))) mod base
In Python:
def FindInPlace(number, base, place):
return number//base**(place-1) % base
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With