Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Basic Calculations /  Integers /

5.1 Digits and Number Bases

Extracting lists of digits.

With only one argument, IntegerDigits assumes the base is 10.

In[1]:= IntegerDigits[n = 1234135634]

Out[1]=

This is the list of base 100 digits for .

In[2]:= IntegerDigits[n, 100]

Out[2]=

Here is the list of base 16 digits for the same number.

In[3]:= IntegerDigits[n, 16]

Out[3]=

Numbers in other bases.

The number in base 2 is in base 10, since .

In[4]:= 2^^100101

Out[4]=

This prints in base 2.

In[5]:= BaseForm[37, 2]

Out[5]//BaseForm=

When the base is larger than 10, extra digits are represented by letters a-z.

Here is a number in base 16.

In[6]:= 16^^ffffaa00

Out[6]=

You can do computations with numbers in base 16. Here the result is given in base 10.

In[7]:= 16^^fffaa2 + 16^^ff - 1

Out[7]=

This gives the result in base 16.

In[8]:= BaseForm[%, 16]

Out[8]//BaseForm=

You can give approximate real numbers, as well as integers, in other bases.

In[9]:= 2^^101.100101

Out[9]=

Here is the beginning of the octal expansion of .

In[10]:= BaseForm[N[Sqrt[2], 30], 8]

Out[10]//BaseForm=

Extracting lists of digits.

This gives a list of decimal digits, together with the number of digits that appear to the left of the decimal point.

In[11]:= RealDigits[y = 123.4567891011121314151617181920]

Out[11]=

RealDigits is similar to IntegerDigits.

In[12]:= RealDigits[y, 100]

Out[12]=

Other Mathematica TE functions related to number representation. (See Section 3.2.)

Another Mathematica TE function related to number formatting. (See Section 3.2.)

Mathematica TE options for number formatting. (See Section 3.2.)