Digits in Numbers

Converting between numbers and lists or strings of digits.

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

IntegerDigits[1234135634,16]

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

RealDigits[123.4567890123456]

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:

FromDigits[%,2]

Here is 56 as a binary string:

IntegerString[56, 2]

This reconstructs the original number again:

FromDigits[%,2]

Numbers in other bases.

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

The number (Subscript[100101, 2]) in base 2 is 37 in base 10:

2^^100101

This prints 37 in base 2:

BaseForm[37,2]

This gives the base 2 representation as a string:

IntegerString[37,2]

Here is a number in base 16:

16^^ffffaa00

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:

BaseForm[%,16]

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

2^^101.100101

Here are the first few digits of (Sqrt[2]) in octal:

BaseForm[N[Sqrt[2],30],8]

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

RealDigits[Sqrt[2],8,15]

This gives 15 octal digits starting with the coefficient of (8^(-10)):

RealDigits[Sqrt[2],8,15,-10]

"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 (RefLink[MantissaExponent, paclet:ref/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:

MantissaExponent[3.45 10^125]