Bit Length

Author

Eric W. Weisstein
November 2, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/IntegerSequences/BitLength.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/BitLength.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Code

MyBitLength[n_]:=Floor[Log2[n]]+1
SetAttributes[MyBitLength,Listable]

MyBitLength2[n_]:=Ceiling[Log2[n+1]]
SetAttributes[MyBitLength2,Listable]

Identities

FunctionExpand[BitLength[n],n∈Integers&&n>0]

FunctionExpand[IntegerLength[n,2],n∈Integers&&n>0]

FunctionExpand[IntegerLength[n],n∈Integers&&n>0]

Table

l1=BitLength[Range[100]]

l2=MyBitLength[Range[100]]

l3=MyBitLength2[Range[100]]

Union/@{l1-l2,l1-l3}

Plots

GraphicsGrid[Partition[Table[ListPlot[BitLength[Range[2^n]],
Joined->True,PlotRange->All,PlotStyle->Red,AxesLabel->{HoldForm[n],BL[HoldForm[n]]}],{n,5,10}],3],ImageSize->400,Spacings->{-40,0}]