[edit] Challenge

Given a number x and the number of places from the right i, find the digit at the ith place. If i = 0, then find the number in the "ones" column.

[edit] Background

This problem actually came from needing to convert a number from binary to decimal. Isolating a digit was a key part of the equation. The formula I found will work for isolating a digit of any number, not just binary numbers. The general concept goes like this: Remove numbers to the right of the number in the ith place and remove numbers to the left of the digit in the ith place. In the following example, we will refer to the digit in the ith place as the target digit.

[edit] Example

In this example we will use x = 52,849 and attempt to isolate the number 8. That number is in the 100’s place so i = 2.

Step General Formula Example Explination
1.1 Image:isolate-gen-11.png Image:isolate-ex-11.png Move target digit to the "ones" place
That is a good start towards isolating the target digit, but we still need to remove the numbers to the left and to the right.
1.2 Image:isolate-gen-12.png Image:isolate-ex-12.png Remove decimals using floor function
Here we use the floor function to remove the decimal part of the number. The floor function simply returns the nearest integer that is less than or equal to the digit inside the brackets. Now we need to remove the numbers to the left of the target digit.
2.1 Image:isolate-gen-21.png Image:isolate-ex-21.png Isolate digits to the left of target digit
In this step we simply isolated the digits to the left of the target digit. We will eventually need to subtract them from value we found in step 1.2. First we need to multiply 52 by 10 so that it represents its actual value (520) instead of just representing the numbers to the left of the target digit.
2.2 Image:isolate-gen-22.png Image:isolate-ex-22.png Move digits to the left into their proper position
Now we know the value of the digits to left of the target digit, and we can use the floor function to remove the digits to the right of the target digit. If we simply subtract these numbers, we can isolate the target digit.
3 Image:isolate-gen-3.png Image:isolate-ex-3.png Fully isolate digit i places from the right