({{, (RefLink[BaseForm, paclet:ref/BaseForm])[expr,n]
prints with the numbers in expr given in base n. }})

OpenersNotesSection(Spacer1)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 exponent is still given in base 10. »

You can mix (RefLink[BaseForm, paclet:ref/BaseForm]) with (RefLink[NumberForm, paclet:ref/NumberForm]) and related functions. »

(RefLink[BaseForm, paclet:ref/BaseForm]) acts as a "wrapper", which affects printing but not evaluation.

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

A binary integer:

BaseForm[33,2]

A binary real:

BaseForm[RandomReal[5],2]

Represent single-digit hexadecimal numbers:

BaseForm[Range[0,15],16]

OpenersExampleSection1(Spacer1)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]

A vector of reals in base 8:

v=RandomReal[10,5]

BaseForm[v,8]

A matrix:

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]

OpenersExampleSection2(Spacer1)Properties & Relations  (5)

Exponents are given in base 10:

BaseForm[10.^6,5]

Input a number in base 16:

16^^612ad

Output in base 16:

BaseForm[%,16]

(RefLink[BaseForm, paclet:ref/BaseForm]) formats numbers in a given base:

BaseForm[123456,2]

(RefLink[IntegerDigits, paclet:ref/IntegerDigits]) gives a list of the digits:

IntegerDigits[123456,2]

Convert back to base 10:

FromDigits[%,2]

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

(RefLink[RealDigits, paclet:ref/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 (RefLink[RealDigits, paclet:ref/RealDigits]) output:

N[digits.(2^(intdigits-Range[Length[digits]]))]

Convert a number to base 2:

base2=BaseForm[21.345,2]

Represent the number to be precise to 3 decimal digits using (RefLink[NumberForm, paclet:ref/NumberForm]):

NumberForm[base2,3]

(RefLink[PaddedForm, paclet:ref/PaddedForm]):

PaddedForm[base2,3]

(RefLink[EngineeringForm, paclet:ref/EngineeringForm]):

EngineeringForm[base2,3]

(RefLink[ScientificForm, paclet:ref/ScientificForm]):

ScientificForm[base2,3]

(RefLink[AccountingForm, paclet:ref/AccountingForm]):

AccountingForm[base2,3]

OpenersExampleSection3(Spacer1)Possible Issues  (1)

The base must be an integer between 2 and 36:

BaseForm[12345,37]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

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

Table[BaseForm[1/2.,i],{i,2,10}]//TableForm

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[IntegerDigits, paclet:ref/IntegerDigits])  ▪  (RefLink[IntegerString, paclet:ref/IntegerString])  ▪  (RefLink[RealDigits, paclet:ref/RealDigits])  ▪  (RefLink[NumberForm, paclet:ref/NumberForm])  ▪  (RefLink[FromLetterNumber, paclet:ref/FromLetterNumber])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Output Formats for Numbers, paclet:tutorial/OutputFormatsForNumbers])}, {▪(RefLinkPlain[Digits in Numbers, paclet:tutorial/DigitsInNumbers])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Display of Numbers, paclet:guide/DisplayOfNumbers])}, {▪(RefLinkPlain[Number Digits, paclet:guide/NumberDigits])}})}})