3.1.3 Digits in Numbers
Converting between numbers and lists of digits.
|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 |
|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] ||reconstruct a number from its decimal digit sequence |
|FromDigits[list, b] ||reconstruct a number from its digit sequence in base b |
|Here is the list of base 16 digits for an integer. || |
|This gives a list of digits, together with the number of digits that appear to the left of the decimal point. || |
|Here is the binary digit sequence for 56, padded with zeros so that it is of total length 8. || |
IntegerDigits[56, 2, 8]
|This reconstructs the original number from its binary digit sequence. || |
Numbers in other bases.
|b^^nnnn ||a number in base b |
|BaseForm[x, b] ||print with x in base b|
When the base is larger than 10, extra digits are represented by letters a-z.
|This prints in base 2. || |
|Here is a number in base 16. || |
|You can do computations with numbers in base 16. Here the result is given in base 10. || |
16^^fffaa2 + 16^^ff - 1
|This gives the result in base 16. || |
|You can give approximate real numbers, as well as integers, in other bases. || |
|Here are the first few digits of in octal. || |
BaseForm[N[Sqrt, 30], 8]
|This gives an explicit list of the first 15 octal digits. || |
RealDigits[Sqrt, 8, 15]
|This gives 15 octal digits starting with the coefficient of . || |
RealDigits[Sqrt, 8, 15, -10]
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.
|MantissaExponent[x] ||give a list containing the mantissa and exponent of x |
|MantissaExponent[x, b] ||give the mantissa and exponent in base b |
|This gives a list in which the mantissa and exponent of the number are separated. || |