- Convert a number, represented as a sequence of digits in one base, to any other base.
- Implement general base conversion. Given a number in base a, represented as a sequence of digits, convert it to base b.
Off the bat, this challenge doesn't read as difficult, but it require additional understanding of logarithms.
Though I did study math up to Calculus 2 in college, little to none of that is within my immediate recollection, which is to say– I don't remember any of it. Never one to give up and always one ready for distraction, I quickly found myself down the rabbit hole of researching math for programming. But eventually, I back to the problem I needed to learn how to solve.
So, because of procrastination, this blog post will only be part one of solving the challenge above. This post will be a review of what logarithms are.
Along the way, the best video I found to quickly bring me up to speed was by the logarithms The Organic Chemistry Tutor. He does a great job explaining the process for evaluating logarithms and provides some examples for you to test your understanding. I've included some cliffnotes below the video.
- Logarithm refers to the power you must raise one number to achieve another number
- Given log3(9) = 2 because 32 = 9
- 3 represents the base, which is the number you start with
- 9 is the argument, or the number you're ending with
- 2 is the exponent, aka the answer, aka the power to which you must raise the base in order end up with the answer
- log1 = 0
- This is because, if the base isn't specified, it is assumed to be 10
- log100 = log10(100) = 2
- Logarithms are the inverse of exponents
- log3(9) = 2 because 32 = 9
- log9(3) = (½)
- If the base is larger than the argument, the answer will be a fraction corresponding fraction.
- Meaning if the log3(9) = 2, log9(2) = ½
- Similarly, if the base is smaller, the answer will be a whole number
- since log2(8) = 3 and log8(2) = 1⁄3
- If the argument is a whole number, the answer will be a positive number
- If the argument is a fraction, the answer will be a negative number
- log31⁄9 = -(2)
- log91⁄3 = -(½)
I also recommend checking out the Logarithm article on Simple Wikipedia
Part 2 will cover changing the base of a logarithm. As always, let me know if you have any questions or suggestions for the next blog post.