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 az. »
  • 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 exponent is 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 allclose all

Basic Examples  (2)

A binary integer:

A binary real:

Represent single-digit hexadecimal numbers:

Scope  (5)

Represent a random number in bases 2 through 36:

A complex number formatted in base 3:

An arbitrary-precision number in base 5:

A vector of reals in base 8:

A matrix:

A mixed symbolic and numeric expression with numbers represented in base 12:

Properties & Relations  (7)

Exponents are given in base 10:

Input a number in base 16:

Output in base 16:

BaseForm formats numbers in a given base:

IntegerDigits gives a list of the digits:

Convert back to base 10:

IntegerString gives the digits as a string:

Convert the string back to a base-10 number:

Format a real number in base 2:

RealDigits gives a list of the digits and number of digits to the left of the decimal:

Reconstruct the base-10 number from RealDigits output:

Convert a number to base 2:

Represent the number to be precise to 3 decimal digits using NumberForm:

PaddedForm:

EngineeringForm:

ScientificForm:

AccountingForm:

The typeset form of BaseForm[expr,n] is interpreted the same as expr when used in input:

Copy the output and paste it into an input cell. The 11110112 is interpreted as 123:

When an input evaluates to BaseForm[expr,n], BaseForm does not appear in the output:

Out is assigned the value 123, not BaseForm[123,2]:

Possible Issues  (2)

The base must be an integer between 2 and 36:

Even when an output omits BaseForm from the top level, it is not stripped from subexpressions:

The output does not have BaseForm in it:

However, the variable e does have BaseForm in it, which may affect subsequent evaluations:

The product is not evaluated due to the intervening BaseForm:

Assign variables first and then apply BaseForm to the result to maintain computability:

Neat Examples  (1)

Expansions in different bases can be terminating or non-terminating for the same number:

Wolfram Research (1988), BaseForm, Wolfram Language function, https://reference.wolfram.com/language/ref/BaseForm.html.

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_2024_baseform, author="Wolfram Research", title="{BaseForm}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/BaseForm.html}", note=[Accessed: 23-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_baseform, organization={Wolfram Research}, title={BaseForm}, year={1988}, url={https://reference.wolfram.com/language/ref/BaseForm.html}, note=[Accessed: 23-November-2024 ]}