Real numbers

To get the radix r representation of a real number its integer and fractional parts are dealt with separately. The function Radix gives two lists, the first one contains the digits of the integer part of x in base r, and the second one has the first d digits of the fractional part of x in base r. The number x is originally in base 10. Of course, it relies on the previously defined functions for integer and fractional parts.

Clear[Radix]

Radix[x_, r_, d_] := {R[IntegerPart[x], r], RR[FractionalPart[x], r, d]}

As a first example we find the binary representation of π, up to 25 binary digits.

Radix[Pi, 2, 25]

{{1, 1}, {0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1}}

This example expresses the first 54 digits of the base 26 representation of π as the letters of the alphabet.

Radix[Pi, 26, 53]

FromCharacterCode[% + 65]

{D, DRSQLOLYRTRODNLHNQTGKUDQGTUIRXNEQBCKBSZIVQQVGDMELMUEX}

Another example in base 26 using the letters of the alphabet as digits. Note that we obtain an answer consistent with a previous example with function R.

Radix[10^6, 26, 5]

{{2, 4, 23, 7, 14}, {0, 0, 0, 0, 0}}

FromCharacterCode[% + 65]

{CEXHO, AAAAA}

Radix[1/7, 10, 20]

{{}, {1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7, 1, 4}}

Radix[1/7, 2, 20]

{{}, {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}}

Radix[1/7, 7, 10]

{{}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}}

Radix[1/7, 3, 20]

{{}, {0, 1, 0, 2, 1, 2, 0, 1, 0, 2, 1, 2, 0, 1, 0, 2, 1, 2, 0, 1}}

Radix[1/7, 4, 20]

{{}, {0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2}}

Radix[1/7, 5, 20]

{{}, {0, 3, 2, 4, 1, 2, 0, 3, 2, 4, 1, 2, 0, 3, 2, 4, 1, 2, 0, 3}}

Radix[1/7, 6, 20]

{{}, {0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5}}

Radix[1/7, 8, 20]

{{}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}

Radix[1/7, 9, 20]

{{}, {1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2}}

Radix[1/7, 11, 20]

{{}, {1, 6, 3, 1, 6, 3, 1, 6, 3, 1, 6, 3, 1, 6, 3, 1, 6, 3, 1, 6}}

Radix[1/7, 26, 20]

{{}, {3, 18, 14, 22, 7, 11, 3, 18, 14, 22, 7, 11, 3, 18, 14, 22, 7, 11, 3, 18}}

FromCharacterCode[% + 65]

{, DSOWHLDSOWHLDSOWHLDS}


Created by Mathematica  (June 3, 2006) Valid XHTML 1.1!