MATHEMATICA TUTORIAL

# Digits in Numbers

 IntegerDigits[n] a list of the decimal digits in the integer n IntegerDigits[n,b] the digits of n in base b IntegerDigits[n,b,len] the list of digits padded on the left with zeros to give total length len IntegerLength[n] the number of decimal digits in n IntegerLength[n,b] the number of base b digits in n IntegerExponent[n,b] the number of zeros at the end of n in base b RealDigits[x] a list of the decimal digits in the approximate real number x, together with the number of digits to the left of the decimal point RealDigits[x,b] the digits of x in base b RealDigits[x,b,len] the first len digits of x in base b RealDigits[x,b,len,n] the first len digits starting with the coefficient of FromDigits[list] construct a number from its decimal digit sequence FromDigits[list,b] construct a number from its digit sequence in base b FromDigits["string"] construct an integer from a string of digits FromDigits["string",b] construct an integer from a string of digits in base b IntegerString[n] a string of the decimal digits in the integer n IntegerString[n,b] a string of the digits of n in base b

Converting between numbers and lists or strings of digits.

Here is the list of base 16 digits for an integer.
 Out[1]=
This gives a list of digits, together with the number of digits that appear to the left of the decimal point.
 Out[2]=
Here is the binary digit sequence for 56, padded with zeros so that it is of total length 8.
 Out[3]=
This reconstructs the original number from its binary digit sequence.
 Out[4]=
Here is 56 as a binary string.
 Out[5]=
This reconstructs the original number again.
 Out[6]=
 b^^nnnn a number in base b BaseForm[x,b] print with x in base b IntegerString[n,b] a string representing n in base b

Numbers in other bases.

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

The number in base 2 is in base 10.
 Out[7]=
This prints 37 in base 2.
 Out[8]//BaseForm=
This gives the base 2 representation as a string.
 Out[9]=
Here is a number in base 16.
 Out[10]=
You can do computations with numbers in base 16. Here the result is given in base 10.
 Out[11]=
This gives the result in base 16.
 Out[12]//BaseForm=
You can give approximate real numbers, as well as integers, in other bases.
 Out[13]=
Here are the first few digits of in octal.
 Out[14]//BaseForm=
This gives an explicit list of the first 15 octal digits.
 Out[15]=
This gives 15 octal digits starting with the coefficient of .
 Out[16]=

"Output Formats for Numbers" 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.

 MantissaExponent[x] give a list containing the mantissa and exponent of x MantissaExponent[x,b] give the mantissa and exponent in base b

Separating the mantissa and exponent of numbers.

This gives a list in which the mantissa and exponent of the number are separated.
 Out[17]=

## Tutorial CollectionTutorial Collection

New to Mathematica? Find your learning path »
Have a question? Ask support »