BaseForm[expr,n]
prints with the numbers in expr given in base n.
BaseForm
BaseForm[expr,n]
prints with the numbers in expr given in base n.
Details
- The maximum allowed base is 36. For bases larger than 10, additional digits are chosen from the letters a–z. »
- You can enter a number in an arbitrary base using base^^digits. »
- When a number in an arbitrary base is given in scientific notation, the base and exponent are still given in base 10. »
- You can mix BaseForm with NumberForm and related functions. »
- The typeset form of BaseForm[expr] is interpreted the same as expr when used in input. »
- When an input evaluates to BaseForm[expr], BaseForm does not appear in the output. »
Examples
open all close allBasic Examples (2)
Scope (5)
Represent a random number in bases 2 through 36:
num = RandomReal[]Table[BaseForm[num, i], {i, 2, 36}]A complex number formatted in base 3:
BaseForm[RandomComplex[], 3]An arbitrary-precision number in base 5:
BaseForm[N[Pi, 20], 5]v = RandomReal[10, 5]BaseForm[v, 8]m = RandomReal[10, {3, 3}]BaseForm[m, 8]A mixed symbolic and numeric expression with numbers represented in base 12:
BaseForm[3.3Sin[50 + x / 7], 12]Properties & Relations (7)
Exponents are given in base 10:
BaseForm[10. ^ 16, 12]16^^612adBaseForm[%, 16]BaseForm formats numbers in a given base:
BaseForm[123456, 2]IntegerDigits gives a list of the digits:
IntegerDigits[123456, 2]FromDigits[%, 2]IntegerString gives the digits as a string:
IntegerString[123456, 2]Convert the string back to a base-10 number:
FromDigits[%, 2]Format a real number in base 2:
BaseForm[123.456, 2]RealDigits gives a list of the digits and number of digits to the left of the decimal:
{digits, intdigits} = RealDigits[123.456, 2]Reconstruct the base-10 number from RealDigits output:
N[digits.(2 ^ (intdigits - Range[Length[digits]]))]base2 = BaseForm[2145678.345, 12]Represent the number to be precise to 3 decimal digits using NumberForm:
NumberForm[base2, 3]PaddedForm[base2, 3]EngineeringForm[base2, 3]ScientificForm[base2, 3]AccountingForm[base2, 3]The typeset form of BaseForm[expr,n] is interpreted the same as expr when used in input:
{BaseForm[123, 2]}Copy the output and paste it into an input cell. The 11110112 is interpreted as 123:
{123}When an input evaluates to BaseForm[expr,n], BaseForm does not appear in the output:
BaseForm[123, 2]Out is assigned the value 123, not BaseForm[123,2]:
%Possible Issues (2)
The base must be an integer between 2 and 36:
BaseForm[12345, 37]Even when an output omits BaseForm from the top level, it is not stripped from subexpressions:
e = BaseForm[123, 2]The output does not have BaseForm in it:
%However, the variable e does have BaseForm in it, which may affect subsequent evaluations:
FullForm[e]The product is not evaluated due to the intervening BaseForm:
2 * eAssign variables first and then apply BaseForm to the result to maintain computability:
BaseForm[f = 123, 2]2 * fTech Notes
Related Guides
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), BaseForm, Wolfram Language function, https://reference.wolfram.com/language/ref/BaseForm.html.
CMS
Wolfram Language. 1988. "BaseForm." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BaseForm.html.
APA
Wolfram Language. (1988). BaseForm. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BaseForm.html
BibTeX
@misc{reference.wolfram_2026_baseform, author="Wolfram Research", title="{BaseForm}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/BaseForm.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_baseform, organization={Wolfram Research}, title={BaseForm}, year={1988}, url={https://reference.wolfram.com/language/ref/BaseForm.html}, note=[Accessed: 13-June-2026]}