Skip to content

IntegerLength ​

The number of digits of nn in the given base — base 10 by default.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageIntegerLength✓
IntegerLength(n)the number of base-10 digits of nn
IntegerLength(n, base)the number of digits in the given base
Typed signatures
TypePackageApplies
(integer, integer?) -> integernumeralsalways

Domain: Numeral systems

Details
  • The sign of nn is not counted — IntegerLength(-123) is 3, same as IntegerLength(123)
  • IntegerLength(0) is 0, unlike IntegerDigits's one-element {0} — there is no shortest numeral for 0, only the empty one

Examples

Basic #
live ↗
InIntegerLength(12 345)\mathrm{IntegerLength}(12\,345)Out55

Number of decimal digits

live ↗
InIntegerLength(123 456 789)\mathrm{IntegerLength}(123\,456\,789)Out99

100!100! takes 525 bits

live ↗
InIntegerLength(100!,2)\mathrm{IntegerLength}(100!, 2)Out525525
Scope #
live ↗
InIntegerLength(2100)\mathrm{IntegerLength}(2^{100})Out3131

255=ff16255 = \mathrm{ff}_{16}

live ↗
InIntegerLength(255,16)\mathrm{IntegerLength}(255, 16)Out22

Listable

live ↗
InIntegerLength([1,10,100])\mathrm{IntegerLength}(\bigl\lbrack1, 10, 100\bigr\rbrack)Out[1,2,3]\bigl\lbrack1, 2, 3\bigr\rbrack
Possible issues #

the sign is not counted

live ↗
InIntegerLength(−123)\mathrm{IntegerLength}(-123)Out33

0 has length 0, unlike its one-element IntegerDigits

live ↗
InIntegerLength(0)\mathrm{IntegerLength}(0)Out00
About
Examples8
Checked againstWolfram Language 8 agree
CrosswalkWolfram Language

See also: IntegerDigits, IntegerReverse, IntegerString