Convert Base16 to Base10

84 Views Asked by At

I am currently trying to use Y-Cruncher to calculate Pi.

Upon calculating 100 digits of Pi, I get this result: 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

However, Y-Cruncher also calculates the hex value of pi: 3.243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c89452821e638d01377be54

After putting the hex value through an online converter, the hex value does not match the decimal value. I am certain that the hex value of pi isn't wrong, because when checking the official value of pi in hex, (https://api.pi.delivery/v1/pi?start=0&numberOfDigits=85&radix=16), it matches exactly. How does one convert the hex value of pi to the decimal value of pi?

1

There are 1 best solutions below

13
On BEST ANSWER

Generic procedure:

Assume that $d_1, \cdots, d_n$ are the known base 16 digits, to the right of the decimal point.

Assume that $x_1, \cdots, x_r$ are the to be determined base 10 digits.

Note that since each prime factor of $(16)$ is also a prime factor of $(10)$, that $r$ must be finite. That is, the expansion of the base 16 number with $n$ digits after the decimal point must be expressible by a finite number of base $10$ decimal digits.

More explicitly:

$(16)^n$ is a divisor of $\left[(10)^4\right]^n.$

Therefore, $r$ is bounded above by $(4n)$.


Let $$T_0 = \sum_{i=1}^n \frac{d_i}{(16)^i}.$$

Find $x_1 \in \{0,1,2,\cdots,9\}$ such that $$\frac{x_1}{10} \leq T_0 < \frac{x_1 + 1}{10}.$$

Compute

$$T_1 = T_0 - \frac{x_1}{10}.$$

Then, continue the iterative process, which should only take a finite number of steps:

Find $x_k \in \{0,1,2,\cdots,9\}$ such that $$\frac{x_k}{(10)^k} \leq T_{k-1} < \frac{x_1 + 1}{(10)^k}.$$

Compute

$$T_k = T_{k-1} - \frac{x_k}{(10)^k}.$$

After a finite number of steps, you will have computed $x_1, \cdots, x_r$ and $T_r$ will equal $0$.