BitLength[n]
gives the number of binary bits necessary to represent the integer n.
BitLength
BitLength[n]
gives the number of binary bits necessary to represent the integer n.
Examples
open all close allBasic Examples (2)
Scope (2)
Plot BitLength for a wide range of positive values:
DiscretePlot[BitLength[n], {n, 2 ^ 10 - 1}, PlotRange -> All]Integers of any size are supported:
BitLength[1000!]Properties & Relations (4)
BitLength[0] is 1:
BitLength[0]For positive n, BitLength[n] is equivalent to Floor[Log[2,n]]+1:
With[{n = RandomInteger[{1, 2 ^ 32 - 1}]}, BitLength[n] == Floor[Log[2, n]] + 1]For negative n, BitLength[n] is equivalent to BitLength[BitNot[n]]:
With[{n = RandomInteger[{1, 2 ^ 32 - 1}]}, BitLength[n] == BitLength[BitNot[n]]]BitLength is symmetric about
:
DiscretePlot[BitLength[n], {n, -20, 20}, PlotMarkers -> {Automatic, 8}]Tech Notes
Related Guides
History
Text
Wolfram Research (2007), BitLength, Wolfram Language function, https://reference.wolfram.com/language/ref/BitLength.html.
CMS
Wolfram Language. 2007. "BitLength." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BitLength.html.
APA
Wolfram Language. (2007). BitLength. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BitLength.html
BibTeX
@misc{reference.wolfram_2026_bitlength, author="Wolfram Research", title="{BitLength}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/BitLength.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_bitlength, organization={Wolfram Research}, title={BitLength}, year={2007}, url={https://reference.wolfram.com/language/ref/BitLength.html}, note=[Accessed: 13-June-2026]}