This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / The Mathematica Book / Advanced Mathematics in Mathematica / Numbers /

3.1.3 Digits in Numbers

Converting between numbers and lists of digits.

Here is the list of base 16 digits for an integer.

In[1]:= IntegerDigits[1234135634, 16]

Out[1]=

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

In[2]:= RealDigits[123.4567890123456]

Out[2]=

Here is the binary digit sequence for 56, padded with zeros so that it is of total length 8.

In[3]:= IntegerDigits[56, 2, 8]

Out[3]=

This reconstructs the original number from its binary digit sequence.

In[4]:= FromDigits[%, 2]

Out[4]=

Numbers in other bases.

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

The number in base 2 is in base 10.

In[5]:= 2^^100101

Out[5]=

This prints in base 2.

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

Out[6]//BaseForm=

Here is a number in base 16.

In[7]:= 16^^ffffaa00

Out[7]=

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

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

Out[8]=

This gives the result in base 16.

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

Out[9]//BaseForm=

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

In[10]:= 2^^101.100101

Out[10]=

Here are the first few digits of in octal.

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

Out[11]//BaseForm=

This gives an explicit list of the first 15 octal digits.

In[12]:= RealDigits[Sqrt[2], 8, 15]

Out[12]=

This gives 15 octal digits starting with the coefficient of .

In[13]:= RealDigits[Sqrt[2], 8, 15, -10]

Out[13]=

Section 2.9.7 describes how to print numbers in various formats. If you want to create your own formats, you will often need to use MantissaExponent to separate the pieces of real numbers.

Separating the mantissa and exponent of numbers.

This gives a list in which the mantissa and exponent of the number are separated.

In[14]:= MantissaExponent[3.45 10^125]

Out[14]=