({{, (RefLink[BitLength, paclet:ref/BitLength])[n] 
gives the number of binary bits necessary to represent the integer n. }})

OpenersNotesSection(Spacer1)Details

For positive n, (RefLink[BitLength, paclet:ref/BitLength])[n] is effectively an efficient version of (RefLink[Floor, paclet:ref/Floor])[(RefLink[Log, paclet:ref/Log])[2,n]]+1.

For negative n, it is equivalent to (RefLink[BitLength, paclet:ref/BitLength])[(RefLink[BitNot, paclet:ref/BitNot])[n]].

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

BitLength[32]

Plot it:

DiscretePlot[BitLength[n],{n,-25,25}]

DiscretePlot[BitLength[n],{n,2^11-1}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Log2, paclet:ref/Log2])  ▪  (RefLink[IntegerLength, paclet:ref/IntegerLength])  ▪  (RefLink[IntegerExponent, paclet:ref/IntegerExponent])  ▪  (RefLink[MantissaExponent, paclet:ref/MantissaExponent])  ▪  (RefLink[IntegerDigits, paclet:ref/IntegerDigits])  ▪  (RefLink[BitShiftRight, paclet:ref/BitShiftRight])  ▪  (RefLink[ByteCount, paclet:ref/ByteCount])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Integer and Number Theoretic Functions, paclet:tutorial/IntegerAndNumberTheoreticalFunctions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Bitwise Operations, paclet:guide/BitwiseOperations])}, {▪(RefLinkPlain[Memory Measurement & Optimization, paclet:guide/MemoryMeasurementAndOptimization])}, {▪(RefLinkPlain[Boolean Computation, paclet:guide/BooleanComputation])}, {▪(RefLinkPlain[Integer Functions, paclet:guide/IntegerFunctions])}})}})